Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Last active January 28, 2025 00:23
Show Gist options
  • Select an option

  • Save LinuxIsCool/8a56aa64b6e9ef116705584bfa2d407f to your computer and use it in GitHub Desktop.

Select an option

Save LinuxIsCool/8a56aa64b6e9ef116705584bfa2d407f to your computer and use it in GitHub Desktop.
Deploying a Panel App on Linode with Nginx and Supervisor

Deploying Python Panel with Nginx

Inspired by these documents:

Prepare the Server

ssh root@<ip-address>

sudo apt-get update
sudo apt-get -y upgrade

sudo apt-get -y install build-essential libpq-dev

sudo apt-get -y install nginx

sudo apt-get -y install supervisor

sudo systemctl enable supervisor
sudo systemctl start supervisor

sudo apt-get -y install python3-virtualenv

Create a User

adduser <USER>
gpasswd -a <USER> sudo
su - <USER>

Clone the Project

  1. Create a github Personal Access Token (classic with repo[x] priviledge): https://github.com/settings/tokens
  2. Clone the desired deployment project
git clone https://github.com/<username>/<project>.git

when prompted, use your github username and paste the access token for password.

Install Requirements

virtualenv .
source bin/activate
cd <project>
pip install -r requirements.txt

Test the app

panel serve <project>/app.py --port 5100 --allow-websocket-origin=<ip-address>

Go to <ip-address>:5100 in your browser
ctrl-C to close the app

Perpare Supervisor

cd
vim bin/panel_start

   #!/bin/bash

   DIR=/home/<USER>/<project>

   cd $DIR
   source ../bin/activate

   export PYTHONPATH=$DIR:$PYTHONPATH

   exec panel serve <project>/app.py --port 5100 --allow-websocket-origin=<ip-address>
   # Add more for horizontal scaling
chmod u+x bin/panel_start
chmod o+rx /home/<USER>/
mkdir logs
sudo vim /etc/supervisor/conf.d/<project>.conf

   [program:<project>]
   command=/home/<USER>/bin/panel_start
   user=<USER>
   autostart=true
   autorestart=true
   redirect_stderr=true
   stdout_logfile=/home/<USER>/logs/panel-error.log

Update and run Supervisor:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart <project>
sudo supervisorctl status <project>

Deploying with Nginx

sudo vim /etc/nginx/sites-available/<project>

   upstream myapp { 
       least_conn;            # Use the least-connected strategy 
       server 127.0.0.1:5100; 
      # Add more for horizontal scaling
       
   } 
    
   server { 
    
       location / { 
           proxy_pass http://myapp; 
    
           # all other settings unchanged 
           proxy_set_header Upgrade $http_upgrade; 
           proxy_set_header Connection "upgrade"; 
           proxy_http_version 1.1; 
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
           proxy_set_header Host $host:$server_port; 
           proxy_buffering off; 
       } 
    
   }
sudo ln -s /etc/nginx/sites-available/<project> /etc/nginx/sites-enabled/<project>
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart

The Final Test

Navigate to in your browser.

If you don't see your panel app:

tail logs/panel-error.log
sudo tail /var/log/nginx/error.log
sudo tail /var/log/nginx/access.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment