NGINX basic Reserve Proxy
-
NGINX and dependencies should already be installed.
sudo vi /etc/nginx/sites-available/proxy_example.conf
server { listen 80; location /{ proxy_pass http://1.1.1.1; } }
Proxied:
example.com/images
example.com/text
example.com/videoWebserver defined under proxy_pass like: proxy_pass http://webserver1.example.com
Only for /images proxying
server { listen 80; location /images{ proxy_pass http://1.1.1.1; } }
Proxied:
example.com/images/dog.jpg
example.com/images/animals/cat.jpgto log user information for statistical reasons
server { listen 80; location /{ proxy_pass http://1.1.1.1; include proxy_params; } }
This includes Instruction specified in another file:
cat /etc/nginx/proxy_params proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;
Enable "Website" via softlink:
sudo ln -s /etc/nginx/sites-available/proxy_example.conf /etc/nginx/sites-enabled/proxy.conf
Disbale Default (this is normaly also a softlink so no files will be lost):
sudo rm /etc/nginx/sites-enabled/default
Check Config files for errors:
sudo nginx -t
"-t" parameter tells nginx to test config files
Example Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test if successful
proxy.conf will not be shown in the output but will still be tested