OPNsense Forum

Archive => 20.7 Legacy Series => Topic started by: alec_hs on December 03, 2020, 09:02:10 PM

Title: Reverse Proxy - Site accessible over WAN IP (Solved)
Post by: alec_hs on December 03, 2020, 09:02:10 PM
I currently have 2 sites hosted on a server behind the OPNsense FW that accessible by two sub domians through the NGINX reverse proxy:


I then have a FW rule on the WAN interface that allows port 443 to the WAN address.

The two sites are perfectly accessible and working fine. My issue is that if you browse directly to the WAN IP it shows up the site hosted on Server A Port x. How do I make it so that no site is accessible on the WAN IP.

Separately is it possible to have the NGINX part of OPNsense running off an additional WAN virtual IP i have?
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: fabian on December 03, 2020, 10:04:34 PM
You can simply not open the port on WAN by not creating a firewall rule.
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: alec_hs on December 03, 2020, 10:11:35 PM
But this then means that the sites behind the proxy are not available.  Does NGINX not need the 443 to WAN IP open to accept the traffic to the mapped locations/ upstream servers?
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: Fright on December 04, 2020, 06:49:07 AM
QuoteHow do I make it so that no site is accessible on the WAN IP
you can add new Server in nginx with your wan ip in "Server name" field and manage it (block\deny\redirect etc)
QuoteSeparately is it possible to have the NGINX part of OPNsense running off an additional WAN virtual IP i have?
as @fabian already said: check your fw rule destination address.
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: alec_hs on December 04, 2020, 03:12:43 PM
Hmm ok so I have created a new HTTP server as below:
(https://i.gyazo.com/badbc46b47a36ce763e6eab1555e0f71.png)

Server name is WAN IP but i can't work out where/ how to block it. I tired create a new HTTP location that goes to nowhere but that doesn't seem to do anything as the site on Server A Port y still loads.
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: Fright on December 04, 2020, 03:23:04 PM
try it without locations at all
should reply with 403 (if you have no files in /usr/local/etc/nginx/html/)
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: alec_hs on December 04, 2020, 03:51:10 PM
Nope unfortunately that was first thing i tried - here are FW rules on WAN if that helps get a better idea.
(https://i.gyazo.com/e2586d85b5c1c53b24d2be463ea83f6a.png)
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: Fright on December 04, 2020, 04:03:27 PM
QuoteNope unfortunately that was first thing i tried
a page on the server A opens or what?
there is something wrong with the config. I use this method myself and it works.
whats in the log for the server with ip-name? any request there?
looks like wrong IP in Server Name
Quotehere are FW rules on WAN if that helps get a better idea
no. fw should pass traffic for this ip. its fine. nginx takes care of it
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: alec_hs on December 04, 2020, 04:18:27 PM
Cool ok so what I'm taking from that reply is FW rules are fine but something wrong with the NGINX setup. Thanks for the help with this by the way, much appreciated.

Server A behind FW is running a web gui on port y, I have a the following config in NGINX:


This all works fine and shows the GUI for this application. I then have another HTTP server in NGINX as configured in the pic in previous post with server name as the WAN IP, no files in html dir.

When i navigate to the WAN IP (from a different network) the gui for the application on Server A Port y is shown.
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: Fright on December 04, 2020, 04:29:40 PM
nginx listens all addresses
if the request arrives and its does not match any Server Names in the config, nginx uses the default server config. for now plugin does not support the directive for specifying the default server, so the first server is taken from the config. so I guess there is an error in the server name (error in IP address) and nginx is using the first server in the config to process the request. that is, server A.
in this case, the request log for the server with the ip-name must be empty
Title: Re: Reverse Proxy - Site accessible over WAN IP
Post by: alec_hs on December 08, 2020, 09:00:22 PM
This was solved with Frights help off forums - config ended up all being ok seemed to be an issue with the NGINX config not actually being applied until after a full FW reload.