Setting up a Python[Django/Flask] on VPS
Personal Deployment Guide - Tanjim Reza - 02-08-2023
Must Create Project Dir in /home/projectname
Project Root -> /home/projectname/htdocs/subdomain.domain.com
Nginx | VHost | /etc/nginx/sites-available/projectname
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
{{ssl_certificate_key}}
{{ssl_certificate}}
server_name subdomain.domain.com www.subdomain.domain.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/projectname/htdocs/subdomain.domain.com/projectname.sock;
}
}
pip install gunicorn
pip install whitenoise
Project Service for AutoStartup | /etc/systemd/system/projectname.service
[Unit]
Description=Gunicorn for projects
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/projectname/htdocs/subdomain.domain.com
Environment="PATH=/home/projectname/htdocs/subdomain.domain.com/env/bin"
ExecStart=/home/projectname/htdocs/subdomain.domain.com/env/bin/gunicorn --workers 3 --bind unix:usus.sock --umask 007 DjangoProjectName.wsgi:app
[Install]
WantedBy=multi-user.target
Project Gunicorn Status Check
sudo systemctl start projectname
sudo systemctl enable projectname
sudo systemctl status projectname
** Ignore static errors **
Symlink for Nginx Server Config
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
sudo systemctl daemon-reload
sudo systemctl restart projectname
sudo systemctl restart nginx