- You have a NodeJS server running at 192.168.100.190:3000and you want to proxy it from your public IP with nginx.
- You have Homebrew.
brew install nginx
Start:
nginx
Stop:
nginx -s stop
Restart:
nginx -s reload
Lint:
nginx -t
- Firewall was already disabled.
- Changed nginx port to 80 in nginx.conf.
- Port forward 80 in router settings.
- Public IP now visible.
- Add reverse proxy server block for nginx:
server {
        listen 80;
        server_name 192.168.100.190;
        location / {
            proxy_set_header   X-Forwarded-For $remote_addr;
            proxy_set_header   Host $http_host;
            # node app server IP
            proxy_pass         http://192.168.100.190:3000; 
        }
    }#user  nobody;
# Number of processes should not exceed number of cores #
worker_processes  1;
# MINIMUM (probably too low): worker_connections * 2 file descriptors = 512 #
# No need to multiply by worker_prcocesses as the limit is applied to each worker #
# 1 descriptor for client connection, 1 for proxied server #
# Could be more based on conf. Could be limited by system (ulimit -n) #
worker_rlimit_nofile 1024;
events {
    # Default 1024 #
    worker_connections  256;
}
# Error Log #
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
# Process ID Log #
pid        logs/nginx.pid;
http {
    include       mime.types;
    default_type  application/octet-stream;
    # Access Logs #
    map $request_uri $loggable {
        default                                             1;
        ~*\.(ico|css|js|gif|jpg|jpeg|png|svg|woff|ttf|eot)$ 0;
    }
    # store request body in temp file for debugging #
    # client_body_in_file_only on;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$request_body_file"';
    access_log  logs/access.log  main buffer=32k flush=30m if=$loggable;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
        
    server {
        listen 80;
        server_name ekyc-demo.xyz www.ekyc-demo.xyz;
        
        # Max user upload size #
        client_max_body_size 20M;
        # Uploaded file RAM buffer instead of temp file #
        client_body_buffer_size 20M;
        # Forward the client's IP address to the proxied server #   
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        location / {
            return 403;
        }
    }
        
    server {
        listen 80;
        server_name app1.ekyc-demo.xyz;
        location / {
            proxy_pass         http://localhost:3000;
        }
    }
        
    server {
        listen 80;
        server_name app2.ekyc-demo.xyz;
        location / {
            proxy_pass         http://localhost:5000;
        }
    }
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}- 
Get a Dynamic DNS Service for your domain. Your machine will ping the service to with the latest Public IP address using DDNS client e.g. (https://github.com/troglobit/inadyn). 
- 
In my case, my D-LINK router had a DDNS client. https://www.namecheap.com/support/knowledgebase/article.aspx/9356/11/how-to-configure-a-ddwrt-router 
- 
Therefore, The DNS record will be updated with the latest Public IP address. The DNS servers will always resolve yourdomainname to the latest Public IP address. 
- 
Namecheap provides a free one with their domains. To use it: https://www.namecheap.com/support/knowledgebase/article.aspx/36/11/how-do-i-start-using-dynamic-dns 
- 
Shell script to update DDNS namecheap record. 
#!/usr/bin/env sh
IP4=$(dig @resolver1.opendns.com ANY myip.opendns.com +short)
echo "$IP4"
URL="https://dynamicdns.park-your-domain.com/update?host=%40&domain=ekyc-demo.xyz&password=mypassword&ip=""${IP4}"
echo "$URL"
curl --request GET \
  --url $URLExecuted via a Cronjob. Commands:
- List cronjobs:
crontab -l
- Add cronjob (useful: https://crontab.guru)
crontab -e