Skip to content

Instantly share code, notes, and snippets.

@choyan

choyan/readme.md

Created Dec 30, 2020
Embed
What would you like to do?
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