Internal Server Error when running Gunicorn as a service

9,746

Internal Server Error (HTTP 500) usually indicates that there is a problem with your code, not the Web Server application.

Have you set up logging?
You should log all 500 errors to a file in your django project, so that you can see why the error is occurring.

You can also try switching on Debug mode, which should tell you why the application is failing.

Share:
9,746

Related videos on Youtube

Matt McCormick
Author by

Matt McCormick

Updated on September 18, 2022

Comments

  • Matt McCormick
    Matt McCormick almost 2 years

    I'm trying to deploy my Django app for the first time on a Digital Ocean VPS. I've used their Django droplet which setup things like this except I'm not using a virtual environment.

    After adding my code and changing a few things, if I run gunicorn directly from the command line, the site loads.

    However, if I run gunicorn as a service sudo service gunicorn start, I just get an 500 "Internal Service Error". There is no error in the nginx log file. The gunicorn log file does not exist.

    Here is the command I run that works (run from the /home/django directory):

    gunicorn --pythonpath=myproject --bind=0.0.0.0:9000 --config /etc/gunicorn.d/gunicorn.py myproject.wsgi:application
    

    Here is the /etc/init/gunicorn.conf file:

    description "Gunicorn daemon for Django project"
    
    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on runlevel [!12345]
    
    # If the process quits unexpectedly trigger a respawn
    respawn
    
    setuid django
    setgid django
    chdir /home/django
    
    exec gunicorn \
        --name=myproject \
        --pythonpath=myproject \
        --bind=0.0.0.0:9000 \
        --config /etc/gunicorn.d/gunicorn.py \
        myproject.wsgi:application
    

    I'm new to gunicorn and nginx so this is really stumping me.

  • Marcos
    Marcos almost 4 years
    perfect! in this way: vim settings and change DEBUG = True