Nginx Reverse Proxy – Troubleshooting Non-Working Configuration

nginxpfsensePROXYreverse-proxy

For this project at school we got 1 public IP address on which we want to run multiple webservices (Roundcube webmail, nextcloud and webconfigurator for the firewall). On the public IP itself we have a pfSense firewall running, which also takes care of the routing. In the LAN of the firewall we have 3 servers, a mailserver (with webmail), a Nextcloud server and a nginx server which I'm trying to get working as a reverse proxy. First I tried to be able to access the webconfigurator, but it doesn't work and I can't find out why. Here is the configuration:

server {
  server_name pfsense.domain.com;

  location ~ {
    proxy_pass_header Authorization;
    proxy_pass http://10.1.1.2:80;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;
    client_max_body_size 0;
    proxy_read_timeout 36000s;
    proxy_redirect on;
  }
}

The pfSense is on the local IP 10.1.1.2. I forwarded port 80 and 443 to the nginx server, but the configuration doesn't work. The filename is /etc/nginx/sites-available/webservers.conf and I created a symlink in the sites-enabled folder. I copied the configuration from another thread on this Stack Exchange.

Best Answer

I fixed it myself, by just going step by step. I started with this:

   server {
        listen 80;
        location / {
            proxy_pass http://192.x.x.2;
        }
    }

And then I added extra options step by step. I found the options and their descriptions on http://nginx.org/en/docs/http/ngx_http_proxy_module.html. I finally ended up with the following, which works fine!

}
server {
    server_name mail.domain.eu www.mail.domain.eu;
    location / {
        proxy_pass http://10.1.1.4;
        proxy_set_header Host       $http_host;
        proxy_set_header Host       $host;
    }
Related Topic