Nginx


  1. https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms
  2. https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching

notes

location

proxy_pass

forward vs. reverse proxy

  1. https://stackoverflow.com/questions/224664/difference-between-proxy-server-and-reverse-proxy-server

https://stackoverflow.com/a/366212/3632318

What is different this time compared to a “forward proxy”, is that this time the user X does not know he is accessing Z, because the user X only sees he is communicating with Y. The server Z is invisible to clients and only the reverse proxy Y is visible externally. A reverse proxy requires no (proxy) configuration on the client side.

https://stackoverflow.com/a/14190390/3632318

A proxy is simply a middleman for communication (requests+responses): Client <-> Proxy <-> Server

  • Client proxy: ( Client <-> Proxy ) <-> Server

    The proxy acts on behalf of the client. Client knows about all 3 machines involved in chain. Server doesn’t.

  • Server proxy: Client <-> ( Proxy <-> Server )

    The proxy acts on behalf of the server. Client only knows about proxy. Server knows whole chain.

Seems to me that forward and reverse are simply confusing, perspective-dependent names for client and server proxy.

https://stackoverflow.com/a/28001462/3632318:

forward proxy

reverse proxy

tips

reload/restart Nginx

for some reason restarting Nginx service using init.d script doesn’t work (most likely start-stop-daemon used internally doesn’t stop it correctly):

$ sudo service nginx restart

instead it’s possible to restart Nginx manually:

UPDATE (2020-07-02)

I managed to restart Nginx without any problems with command:

$ sudo systemctl restart nginx.service
$ sudo journalctl -u nginx

proxy POST requests

  1. https://serverfault.com/a/312114

POST requests are passed to proxy just like GET requests, no additional configuration is required.

troubleshooting

open() “/etc/nginx/mime.types” failed (2: No such file or directory)

$ sudo journalctl -u nginx.service
...
nginx[824]: nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:25

solution

$ sudo apt-get autoremove --purge nginx
$ sudo apt-get install nginx

open() “/run/nginx.pid” failed (2: No such file or directory)

$ sudo journalctl -u nginx.service
...
nginx[3257]: nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)

solution

$ sudo systemctl --system restart nginx