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:example]
directory=/home/user/example/example
command=/home/user/envs/example/bin/gunicorn example.wsgi:application
user=user
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/user/envs/example/bin/gunicorn-error.log
[program:serverinterface]
directory=/home/user/example/example
command=/home/user/envs/example/bin/daphne -b 0.0.0.0 -p 8001 example.asgi:application
autostart=true
autorestart=true
stopasgroup=true
user=user
stdout_logfile = /home/user/example/bin/gunicorn-error.log
nginx/sites-availible/example.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://example.com$request_uri;
}
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
server_name example.com www.example.com;
# Let's Encrypt parameters
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.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.
Hi there,
It appears that your Nginx configuration may be missing some
proxy_pass
directives for forwarding the requests to your Gunicorn and Daphne servers. The missingproxy_pass
directive in the@proxy_to_app
location block could be the reason why you are stuck on the Nginx welcome page.Here’s how you might modify your Nginx configuration to correct the issue:
Update the upstream block: Since Gunicorn serves your HTTP requests, define it in the
upstream
block. If you are using a Unix socket for Gunicorn, you can keep it as is; otherwise, you may replace it with the appropriate IP and port.Fix the proxy_pass directives: You will need to specify the appropriate
proxy_pass
directives to route the requests to the upstream app server for HTTP requests and to Daphne for WebSocket requests.Here’s an example of how you can modify the
nginx/sites-available/example.com
file:Once you have made the necessary changes, restart Nginx to apply the new configuration:
Check the Nginx error log if you encounter any issues:
With these modifications, Nginx should forward HTTP requests to Gunicorn and WebSocket requests to Daphne, based on the paths provided in your configuration. Make sure that Gunicorn and Daphne are running, and the paths and ports in the Nginx configuration correspond to their actual locations and ports.
Best,
Bobby