Reputation: 380
So I am running pretty standart setup, I followed the same tutorial I did before but now it doesn't work for unknown reasons.
When I run ./manage.py runserver my_ip:8000
it works fine.
When I run my gunicorn script via bin/gunicorn_start
it works fine and creates the sock file
However when I run gunicorn script via supervisor, and nginx, it results with Internal Server Error
, and no info in error logs. What am I doing wrong? I guess it's gunicorn or permission problems?
#!/bin/bash
NAME="today" # Name of the application
DJANGODIR=~/deployment/today_project/
SOCKFILE=~/deployment/run/gunicorn.sock # we will communicte using this unix socket
USER=ferski # the user to run as
GROUP=ferski # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=today_project.settings # which settings file should Django use
DJANGO_WSGI_MODULE=today_project.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=debug \
--bind=unix:$SOCKFILE
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
...
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
...
[program:today]
command = /home/ferski/deployment/bin/gunicorn_start
user = ferski
stdout_logfile = /home/ferski/deployment/logs/gunicorn_supervisor.log
redirect_stderr = true
...
And finally nginx.conf
upstream today_app_server {
server unix:/home/ferski/deployment/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name haxelita.pl;
client_max_body_size 4G;
access_log /home/ferski/deployment/logs/nginx-access.log;
error_log /home/ferski/deployment/logs/nginx-error.log;
location /static/ {
alias /home/ferski/deployment/today_project/today/static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://today_app_server;
break;
}
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/ferski/deployment/today_project/today/static/;
}
}
Whats wrong here? Is it permission problems?
Upvotes: 4
Views: 4422
Reputation: 21
This problem confused the hell out of me. But I figured it out, I thought i would post it for future reference, since this is the top google search for this error.
uwsgi --socket /path/to/sock --chdir /path/to/django/project/ --module project_name.wsgi --chmod-socket=664
Then you can add in the number of cores and processors but appending this (change 4 to the number of core in your application).
--master --processes 4 --async 4 --ugreen
Upvotes: 2
Reputation: 1930
You can't activate a virtualenv environment through source
in a script that gets started with supervisor. Use directory=/home/ferski/deployment/today_project/
in your supervisord.conf.
See Supervising virtualenv django app via supervisor
Upvotes: 0