Nginx Setup
- sudo vim /etc/nginx/sites-available/
MY_PROJECT
server { listen 80; # if you wanna use subdomains: # server_name DOMAIN SUBDOMAIN_01.DOMAIN SUBDOMAIN_02.DOMAIN; server_name SERVER_DOMAIN_OR_IP; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/USERNAME/MY_PROJECT_DIR; } location / { include proxy_params; proxy_pass http://unix:/run/gunicorn.sock; } }
sudo ln -s /etc/nginx/sites-available/MY_PROJECT /etc/nginx/sites-enabled
- check for syntax errors by
sudo nginx -t
- restart nginx
sudo systemctl restart nginx
- remove 8000 access
sudo ufw delete allow 8000
sudo ufw allow 'Nginx Full'
- run your domain in the browser, all should be running ok
- anytime you change anything in /etc/nginx/* run
service nginx restart
andsystemctl restart gunicorn
- anytime you change anything on server (after
git pull
), restart gunicorn to apply the changessudo systemctl restart gunicorn
Resources:
➡️https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps
➡️https://medium.com/@_christopher/deploying-my-django-app-to-a-real-server-part-i-de78962e95ac
➡️http://rahmonov.me/posts/run-a-django-app-with-nginx-and-gunicorn/