Tuesday, February 20, 2018

Nginx Reverse Proxy

I deployed a web application at Azure and one of the modules creates an e-mail with a link redirecting to one of the pages in the website. It works great (I mean the e-mail module) but I have a problem: The links are written as http://localhost:8080/something.

This is because the web application sees all remote addresses as localhost when it is served publicly with a host name. To solve this problem, we configure Nginx to reverse proxy - a way to trick the web application that all access to it or the remote addresses accessing it is from the IP of the host or the host name instead.

Here's the configuration from https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching

location /match/here {
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://example.com/new/prefix;
}
For more information, please visit https://www.nginx.com/.

No comments:

Post a Comment