All Guides

Nginx Web Server Setup

Install Nginx web server and configure it as a reverse proxy.

Intermediate20 min

Setup Steps

1. Install Nginx:

sudo apt update
sudo apt install nginx -y

2. Start Nginx:

sudo systemctl start nginx
sudo systemctl enable nginx

3. Create a server block:

sudo nano /etc/nginx/sites-available/mysite

4. Configuration content:

server {
    listen 80;
    server_name mysite.com www.mysite.com;
    root /var/www/mysite;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

5. Enable the site:

sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

6. Reverse proxy for Node.js app:

location / {
    proxy_pass http://localhost:3000;
    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;
}

7. Enable gzip compression:

gzip on;
gzip_types text/css application/javascript application/json;