Skip to content

Instantly share code, notes, and snippets.

@choyan
Created December 30, 2020 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choyan/891ca040a79d32dfb04266521e505f7f to your computer and use it in GitHub Desktop.
Save choyan/891ca040a79d32dfb04266521e505f7f to your computer and use it in GitHub Desktop.
Nginx reverse proxy setup for ExpressJS apps

Nginx reverse proxy setup with express server

Install nginx

sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw status
systemctl status nginx
curl -4 icanhazip.com
http://localhost # server_ip

Update nginx confifuration

sudo nano /etc/nginx/sites-available/express-auth.test
 server {
        listen 80;
        server_name express-test.test;
        location / {
            # express port number
            proxy_pass http://localhost:4000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
}
sudo ln -s /etc/nginx/sites-available/express-auth.test /etc/nginx/sites-enabled/
sudo unlink /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

If using local computer

Set the server_name inside hosts local file.

nano /etc/hosts
127.0.0.1       express-auth.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment