OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • nginx listen ip
« previous next »
  • Print
Pages: [1]

Author Topic: nginx listen ip  (Read 8182 times)

patrick7

  • Newbie
  • *
  • Posts: 9
  • Karma: 2
    • View Profile
nginx listen ip
« 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
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: nginx listen ip
« Reply #1 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.
Logged

patrick7

  • Newbie
  • *
  • Posts: 9
  • Karma: 2
    • View Profile
Re: nginx listen ip
« Reply #2 on: October 16, 2018, 08:11:55 am »
I see several usecases.
One is that the webinterface already listens on the same ports :-)
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: nginx listen ip
« Reply #3 on: October 16, 2018, 06:03:53 pm »
Quote from: patrick7 on October 16, 2018, 08:11:55 am
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)
Logged

patrick7

  • Newbie
  • *
  • Posts: 9
  • Karma: 2
    • View Profile
Re: nginx listen ip
« Reply #4 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)
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: nginx listen ip
« Reply #5 on: October 16, 2018, 07:10:25 pm »
Quote from: patrick7 on October 16, 2018, 06:58:57 pm
Use case multiple servers,...

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

Quote from: patrick7 on October 16, 2018, 06:58:57 pm
…, 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?
« Last Edit: October 16, 2018, 07:12:13 pm by fabian »
Logged

patrick7

  • Newbie
  • *
  • Posts: 9
  • Karma: 2
    • View Profile
Re: nginx listen ip
« Reply #6 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...
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: nginx listen ip
« Reply #7 on: October 17, 2018, 06:08:30 pm »
Quote from: patrick7 on October 17, 2018, 01:11:52 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.

Quote from: patrick7 on October 17, 2018, 01:11:52 pm
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).
Logged

Deku

  • Newbie
  • *
  • Posts: 31
  • Karma: 4
    • View Profile
Re: nginx listen ip
« Reply #8 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.
Logged

oxivanisher

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: nginx listen ip
« Reply #9 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 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.
But to make the nginx config "catch all" I would need it to listen on the virtual IP.
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: nginx listen ip
« Reply #10 on: October 01, 2019, 09:45:08 pm »
It is bound to :: and 0.0.0.0 so it will also listen on VIPs
Logged

ip6li

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: nginx listen ip
« Reply #11 on: December 05, 2020, 11:34:03 am »
There are several usecases for binding Nginx to specific IP adresses, e.g.:

  • One IP address may be forwarded by pf to a webservice which cannot be routed through Nginx, e.g because it does not support SNI - that is real life versus theory
  • One mor IP address is routed to e.g. honeypot and Nginx should not interfere

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.
Logged

bimbar

  • Sr. Member
  • ****
  • Posts: 445
  • Karma: 25
    • View Profile
Re: nginx listen ip
« Reply #12 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.
Logged

bimbar

  • Sr. Member
  • ****
  • Posts: 445
  • Karma: 25
    • View Profile
Re: nginx listen ip
« Reply #13 on: October 14, 2021, 07:04:49 pm »
I opened a Pull Request, #2578 .
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • nginx listen ip
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2