1đź‘Ť
EDIT
I am reading again your post, and… Should not you must set ADDRESS in your gunicorn script? gunicorn by default uses port 8000, maybe your subdomain is trying to use the same port?
END EDIT
I have two Django applications running with nginx, gunicorn and supervisor as you want to do (well, not the same, but very similar, i have two domains and a subdomain). I don’t see where is your mistake, I think must be in nginx configuration. Maybe the “root” line?
Have you seen if supervisord returns you an error when you try to start it using “supervisorctl” command?
I can show you my configuration and you can compare it:
I have two .conf files for nginx:
domain1.conf:
server {
listen 80;
server_name domain1.net;
return 301 $scheme://www.domain1.net$request_uri;
}
server {
listen 80;
server_name www.domain1.net;
access_log /var/log/nginx/domain1.log;
location /static {
alias /var/www/domain1/media/;
autoindex on;
access_log off;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://127.0.0.1:8000/;
}
}
and domain2.conf:
server {
listen 80;
server_name subdomain.domain2.es;
access_log /var/log/nginx/domain2.log;
location /static {
alias /var/www/dev/domain2/domain2/static/;
autoindex on;
access_log off;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://127.0.0.1:8005/;
}
}
My two gunicor scripts are the same, just changing paths and ADDRESS in one of them:
#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/domain1.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=1
# user/group to run as
USER=user
GROUP=user
ADDRESS=127.0.0.1:8005
cd /var/www/dev/domain1
source /path/to/venv/domain1/bin/activate
test -d $LOGDIR || mkdir -p $LOGDIR
exec gunicorn_django -w $NUM_WORKERS --bind=$ADDRESS \
--user=$USER --group=$GROUP --log-level=debug \
--log-file=$LOGFILE 2>>$LOGFILE
My two supervisor scripts are the same too:
[program:domain1]
directory = /var/www/dev/domain1/
user = user
command = /path/to/bin/gunicorn_domain1.sh
stdout_logfile = /var/log/nginx/domain1.log
stderr_logfile = /var/log/nginx/domain1.log
I hope you found this helpful.