Here is a simple config for a reverse proxy, it will take all requests coming to our server with a Host header example.com and proxy the to the local port 8080:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
}
}
Standard place to add configs is /etc/nginx/sites-available
So we can create it like this:
vi /etc/nginx/sites-available/example.com.confAnd copy the config from above!
After creating a config in /etc/nginx/sites-available folder we should create a symlink to it from /etc/nginx/sites-enabled, like this:
ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.confThis will allow us to disable config without deleting it completely, modifying, commenting out, etc.
To test, run:
nginx -tIf everything is fine reload nginx using following command:
nginx -s reload