Skip to content

nginx

Created: 2022-01-02 13:06:08 -0800 Modified: 2022-03-31 21:26:02 -0700

Simple reverse proxy to “redirect” all incoming traffic to another server

Section titled Simple reverse proxy to “redirect” all incoming traffic to another server

This is a proxy, not a redirect, so the client has no idea that the nginx server isn’t the same as the web server.

sudo apt -y install nginx
sudo vim /etc/nginx/sites-enabled/default
server {
listen 80;
location / {
proxy_pass http://10.30.66.9:80;
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo /usr/sbin/nginx -s reload

Super easy 80 → 8080 configuration

Section titled Super easy 80 → 8080 configuration

This actually doesn’t involve nginx, but I may want this in the future: https://gist.github.com/kentbrew/776580

sudo iptables -t nat -A PREROUTING -p tcp —dport 80 -j REDIRECT —to-ports 8000

The same thing works for 443, just replace the “80”.

List rules like this: sudo iptables -t nat -L

(if this says “env: iptables: No such file or directory”, then perhaps you aliased sudo and should unalias it)

Delete rules like this: sudo iptables -t nat -D PREROUTING 1