OPNsense Forum

English Forums => General Discussion => Topic started by: patrick7 on October 15, 2018, 10:38:06 am

Title: nginx listen ip
Post by: patrick7 on October 15, 2018, 10:38:06 am
Hi

Is there a possibility to tell a nginx server to listen on which IP?

Regards
Patrick
Title: Re: nginx listen ip
Post by: fabian on October 15, 2018, 06:40:02 pm
no, is there a special use case behind? It listens on ::/0 and 0.0.0.0/0 on the configured ports.
Title: Re: nginx listen ip
Post by: patrick7 on October 16, 2018, 08:11:55 am
I see several usecases.
One is that the webinterface already listens on the same ports :-)
Title: Re: nginx listen ip
Post by: fabian on October 16, 2018, 06:03:53 pm
One is that the webinterface already listens on the same ports :-)

The nginx plugin can serve the web interface instead of the internal server and you probably do already have it but it is disabled in the code.
Try to connect via SSH, search for TODO in the /usr/local/etc/nginx.conf and enable this line, then kill the web interface server (if you do not use the CP it is just killall lighttpd) and then restart nginx. The web interface should be there and the shared port should work.

Just be careful because a config reload will drop the change and you loose access. (to make it more persistent, you have to update the template)
Title: Re: nginx listen ip
Post by: patrick7 on October 16, 2018, 06:58:57 pm
Will try, but even if it's possible to serve the webinterface, there should be a possibility to tell nginx to listen on which ip's.
Use case multiple servers, dedicated IP per website, ...... (endless list)
Title: Re: nginx listen ip
Post by: fabian on October 16, 2018, 07:10:25 pm
Use case multiple servers,...

You can make multiple server blocks. nginx decides based on SNI or Host header.

…, dedicated IP per website, …

Isn't that against the high availability goal? If you think about security, you can also contact the server(s) directly from your internal networks if the WAF is not required. But wouldn't be an IP based ACL more reasonable?
Title: Re: nginx listen ip
Post by: patrick7 on October 17, 2018, 01:11:52 pm
You are right, there are other ways.
But still it should be possible to bind nginx to a single IP. e.g. replace the listen port with just "listen". If someone enters 443, it listens on all IPs, port 443, if you enter 1.2.3.4:443, it listens on IP 1.2.3.4, port 443.
I don't like to bind services to all IPs even if I only need the service on one IP.  For all other services I use that's possible...
Title: Re: nginx listen ip
Post by: fabian on October 17, 2018, 06:08:30 pm
But still it should be possible to bind nginx to a single IP. e.g. replace the listen port with just "listen". If someone enters 443, it listens on all IPs, port 443, if you enter 1.2.3.4:443, it listens on IP 1.2.3.4, port 443.

currently if you choose port 80 for HTTP, you will bind 0.0.0.0:80 and [::]:80. I guess many administrators are confused about [IP] notation or forget it.

I don't like to bind services to all IPs even if I only need the service on one IP.  For all other services I use that's possible...

Most plugins don't support that but many allow to choose an interface and will generate a configuration which will bind to all IP addresses configured on a special interface.
This has some other limitations like it does not work when the IP is replaced or not in the configuration (for example when SLAAC is used).
In some cases the socket breaks and leads to a daemon crash (don't know if this happens in nginx as well but others do some have this issue if you get another IP and the old binding is not valid anymore).
Title: Re: nginx listen ip
Post by: Deku on May 10, 2019, 04:31:15 pm
I would also like a feature to select which interface to listen on.  Another service using the port on another interface is causing me issues.  I don't want it to listen on all interfaces - would be nice to allow the selection and just default to ALL.
Title: Re: nginx listen ip
Post by: oxivanisher on October 01, 2019, 10:12:07 am
I would like that too. My goal is, to implement something like Pi Hole but much simpler. A simple https://forum.fpvhub.ch/t/dns-blacklist-wie-pi-hole-fuer-unbound-dns-server-opn-sense/772 (https://forum.fpvhub.ch/t/dns-blacklist-wie-pi-hole-fuer-unbound-dns-server-opn-sense/772) with a cron entry which rewrites ad- and malicious domains to a given IP. This IP is configured as virtual IP on the firewall, and the nginx could server a site like http://www.shadowandy.net/2014/04/adblocking-nginx-serving-1-pixel-gif-204-content.htm (http://www.shadowandy.net/2014/04/adblocking-nginx-serving-1-pixel-gif-204-content.htm).
But to make the nginx config "catch all" I would need it to listen on the virtual IP.
Title: Re: nginx listen ip
Post by: fabian on October 01, 2019, 09:45:08 pm
It is bound to :: and 0.0.0.0 so it will also listen on VIPs
Title: Re: nginx listen ip
Post by: ip6li on December 05, 2020, 11:34:03 am
There are several usecases for binding Nginx to specific IP adresses, e.g.:


I cannot understand what is wrong with a Nginx config like listen 192.168.1.2:443 ssl http2; it is supported by Nginx out of the box.

Binding services to IP addresses which are not needed for this service should be considered as a security flaw.
Title: Re: nginx listen ip
Post by: bimbar on October 13, 2021, 01:10:03 pm
I do agree, and I have opened (another) feature request: https://github.com/opnsense/plugins/issues/2574 .

We have customers with public /27 networks which are served by an opnsense firewall, and if I can't distinguish between all those IPs in nginx, I might just as well not have them.

I would also do the work for this, but if it's not going to be accepted, then I don't want to waste my time.
Title: Re: nginx listen ip
Post by: bimbar on October 14, 2021, 07:04:49 pm
I opened a Pull Request, #2578 .