Installation
Install Nginx
Install the Nginx web server package.
sudo apt install nginx
Configuration
Create Site Config
Create a new configuration file in sites-available.
sudo nano /etc/nginx/sites-available/billing
Server Block Template
Configure the reverse proxy for Gunicorn and static file serving.
upstream billing_app {
server unix:/run/billing-gunicorn/billing.sock;
}
server {
listen 127.0.0.1:8000;
listen 192.168.1.169:8000;
server_name localhost;
access_log /var/log/nginx/billing_access.log;
error_log /var/log/nginx/billing_error.log;
# ---- ALLOW ONLY LOCAL NETWORK ----
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
location / {
proxy_pass http://billing_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
}
Activation
Enable Site & Restart
Link the config, test, and restart Nginx.
sudo ln -s /etc/nginx/sites-available/billing /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
Test & Restart Nginx
Test and restart Nginx.
sudo nginx -t
sudo systemctl reload nginx
Permissions Fix
Static Files Access
Ensure Nginx has read access to your home and static directories.
sudo chmod 755 /home/user
sudo chmod 755 /home/user/My_Billing
sudo chmod -R 755 /home/user/My_Billing/staticfiles
sudo chown -R user:www-data /home/user/My_Billing/staticfiles
sudo systemctl reload nginx