Nginx Reverse Proxy Setup

This is a short digest of stuff I found online and my own experiences with setting up a reverse proxy dealing with static routing from my local DNS Server. It was strikingly simple to get running (but some trial and error was needed to make it work as I wanted to). Might be I’ll update this one as I go.

On Archlinux Server

  1. Install nginx:

    sudo pacman -S nginx
    
  2. Make your /etc/nginx/nginx.conf look like this:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    worker_processes auto;
    
    events {
        worker_connections 1024;
    }
    
    http {
        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        keepalive_timeout 65;
        client_max_body_size 1G;
    
        server {
            server_name sub.domain.tld;
    
            location / {
                proxy_pass http://192.168.1.3:3000;
            }
        }
    
    }
    

    The above is more or less just a stripped-down version of the default configuration. The important changes I made was using the proxy_pass keyword to redirect the request to the correct server and service port (note URL).

    I also set client_max_body_size to 1G (one gigabyte) because the service I run typically needs to up/download files larger than your typical index.html.

  3. Start nginx with soystemd:

    sudo nginx -t -c /etc/nginx/nginx.conf # Fix any errors reported here
    sudo systemctl enable --now nginx
    sudo systemctl status nginx # Ensure everything's fine