I have been following several different tutorials about how to set up gunicorn and daphne in parallel so that gunicorn can serve http to my django apps and daphne to my django channels app. However, I am now stuck on the welcome to nginx homepage and I cannot figure out what the problem is.
supervisor.conf
[program:mysite]
directory=/home/user/mysite/mysite
command=/home/user/envs/mysite/bin/gunicorn mysite.wsgi:application
user=user
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/user/envs/mysite/bin/gunicorn-error.log
[program:serverinterface]
directory=/home/user/mysite/mysite
command=/home/user/envs/mysite/bin/daphne -b 0.0.0.0 -p 8001 mysite.asgi:application
autostart=true
autorestart=true
stopasgroup=true
user=user
stdout_logfile = /home/user/mysite/bin/gunicorn-error.log
nginx/sites-availible/mysite.com
upstream app_server {
server http://unix:/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://tutoraustria.com$request_uri;
}
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
server_name mysite.com www.mysite.com;
# Let's Encrypt parameters
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location = /favicon.ico { access_log off; log_not_found off; }
location / {
try_files $uri @proxy_to_app;
}
location /ws/ {
try_files $uri @proxy_to_ws;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location @proxy_to_ws {
proxy_pass http://0.0.0.0:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hello,
This typically happens when the configuration for Nginx is not properly set up to pass requests to your application. Here’s a checklist that might help you identify the issue:
Check Nginx Configuration Syntax: Run
sudo nginx -t
to verify that your Nginx configuration file has the correct syntax.Correct File Location: Make sure that your configuration file is symlinked from
sites-available
tosites-enabled
. You can create a symbolic link with:Remove Default Nginx Configuration: The default Nginx configuration may be conflicting with your site’s configuration. You can remove the default symlink in the
sites-enabled
directory:Gunicorn Socket: In the Nginx configuration, you’ve defined
server http://unix:/run/gunicorn.sock;
but you haven’t set up proxy_pass to this socket inlocation @proxy_to_app
. Update it to:Fix the Upstream Server Line: Remove
http://
from theserver
line underupstream app_server
:Check Gunicorn Configuration: Ensure that Gunicorn is correctly configured to use the same socket file that Nginx is expecting (
/run/gunicorn.sock
).Check Supervisor Status: Ensure that both Gunicorn and Daphne are running under Supervisor. You can check the status with:
Check Log Files: Review the Nginx error log (usually at
/var/log/nginx/error.log
) and the Gunicorn log file you defined (/home/user/envs/mysite/bin/gunicorn-error.log
). This might contain useful information regarding the issue.Reload Configuration: After making these changes, don’t forget to reload Nginx:
Best,
Bobby