By laviscoacc
I was following this tutorial for deploying my django project to digitalocean droplet [https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04]. But I have been facing this issue for last 2 days. Here are my configuration files: /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server {
listen 80;
server_name 167.71.233.157;
location / {
proxy_pass http://unix:/run/gunicorn.sock;
}
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
client_max_body_size 100M;
}
/etc/nginx/sites-enabled/lavisco_ecommerce
server {
listen 80;
server_name 167.71.233.157;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/lavisco/Lavisco_Ecommerce;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
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!
Heya, Try some of the following suggestions:
/etc/nginx/nginx.conf)Server Block Inside http Block:
http block. It’s generally recommended to separate individual server configurations into their own files under /etc/nginx/sites-available/ and then create symbolic links to those files in the /etc/nginx/sites-enabled/ directory. This helps keep configurations organized and manageable.Proxy Pass:
proxy_pass directive is using a Unix socket (http://unix:/run/gunicorn.sock;). Ensure that this matches exactly with what Gunicorn is using. Check your Gunicorn service file (typically found at /etc/systemd/system/gunicorn.service) for the --bind option./etc/nginx/sites-enabled/lavisco_ecommerce)Server Block:
Static Files Location:
location /static/) seems correctly configured. Ensure that /home/lavisco/Lavisco_Ecommerce is the correct path where your Django static files are collected (STATIC_ROOT in your Django settings).Gunicorn Proxy Pass:
nginx.conf, this uses the same proxy_pass. Just ensure it’s correctly pointing to the Gunicorn socket.Remove Redundant Server Block:
/etc/nginx/sites-enabled/lavisco_ecommerce is the specific configuration for your Django app, the server block inside nginx.conf might be redundant and could potentially cause conflicts. Consider removing it.Check Symbolic Links:
/etc/nginx/sites-available/lavisco_ecommerce to /etc/nginx/sites-enabled/lavisco_ecommerce. This is typically done using:sudo ln -s /etc/nginx/sites-available/lavisco_ecommerce /etc/nginx/sites-enabled
Nginx and Gunicorn Services:
sudo systemctl status nginx
sudo systemctl status gunicorn
Firewall Configuration:
sudo ufw allow 'Nginx Full'
Error Logs:
/var/log/nginx/error.log) and Gunicorn logs for clues.File Permissions:
www-data) has the necessary permissions to access the Gunicorn socket and the Django project files, especially the static files.Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.