#how to deploy my flask server (python) on digitalocean droplet?

1 messages · Page 1 of 1 (latest)

loud parcel
#

i have got a ssh connection

wanton charm
#
# Step 1
sudo apt update
sudo apt upgrade

# Step 2
sudo apt install python3-pip python3-venv

# Step 3
# NAME means what you want to name it
mkdir NAME
cd NAME
python3 -m venv NAME

# Step 4
source NAME/bin/activate

# Step 5
pip install Flask

# Step 6
# Download source files via Git / SCP/ FTP / etc

# Step 7
pip install gunicorn
sudo nano /etc/systemd/system/NAME-gunicorn.service

# Step 8
# Configuration should look like this: 
[Unit]
Description=Gunicorn instance to serve NAME
After=network.target

[Service]
User=username
Group=groupname
WorkingDirectory=/path/to/NAME
Environment="PATH=/path/to/NAME/NAME/bin"
ExecStart=/path/to/NAME/NAME/bin/gunicorn --workers=3 --bind unix:NAME.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target

# Step 9
sudo systemctl start NAME-gunicorn
sudo systemctl enable NAME-gunicorn

# Step 10
sudo apt install nginx
sudo nano /etc/nginx/sites-available/NAME

# Step 11
# Configuration should have this added: 
server {
    listen 80;
    server_name YOURDOMAIN.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /path/to/NAME;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/path/to/NAME/NAME.sock;
    }
}

# Step 12
sudo ln -s /etc/nginx/sites-available/NAME /etc/nginx/sites-enabled
sudo nginx -t

# Step 13
sudo systemctl restart nginx

# Step 14
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx