Running ERPNext behind Nginx gives you better performance, SSL support, and the ability to serve your site on port 80/443 instead of 8000. This guide covers setting up Nginx as a reverse proxy for ERPNext.

STEP 1 Install Nginx

sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx

STEP 2 Use Bench Setup (Recommended)

Frappe Bench has a built-in command that configures Nginx for you automatically.

cd frappe-bench
sudo bench setup production your-username

This command does everything — creates Nginx config, sets up Supervisor, configures the site. But if you want to do it manually, continue below.

STEP 3 Manual Nginx Configuration

sudo nano /etc/nginx/sites-available/erpnext
upstream frappe-bench {
    server 127.0.0.1:8000 fail_timeout=0;
}

upstream socketio-server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80;
    server_name yourdomain.com;
    root /home/erpnext/frappe-bench/sites;

    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;

    location /assets {
        try_files $uri =404;
    }

    location ~ ^/protected/(.*) {
        internal;
        try_files /$1 =404;
    }

    location /socket.io {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://socketio-server;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://frappe-bench;
    }
}

STEP 4 Enable the Site

sudo ln -s /etc/nginx/sites-available/erpnext /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

STEP 5 Add SSL with Let’s Encrypt

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
sudo systemctl reload nginx

Your ERPNext is now accessible at https://yourdomain.com with full SSL encryption and Nginx handling static files efficiently.

Share this article

Comments

Join the discussion. Got a question, found an issue, or want to share your experience?

Leave a Comment

Your email stays private. We just use it for replies.

Nothing to preview yet.

Use **bold**, *italic*, `code`, ```code blocks```, [link](url), > quote, - list