Link to home
Start Free TrialLog in
Avatar of CEHJ
CEHJFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I change the address on which nginx listens?

This is what is happening at the moment:


tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      -                  
tcp        0      0 127.0.0.1:8081          0.0.0.0:*               LISTEN      -

Open in new window

That's of no use to me whatsoever, since I need to be able to work on this server from anywhere and it is headless.

I attach nginx.conf. I've tried the obvious things without any success.

nginx2.conf

Avatar of Dr. Klahn
Dr. Klahn

The address, or the port number?

The address cannot be changed.  All web servers listen on 127.0.0.1 or "localhost."

The port number can be changed using the "listen" directive.  See the commentary at the link below:

https://www.tecmint.com/change-nginx-port-in-linux/
Maybe I misunderstand the question, as the answer seems clear.

listen X.X.X.X:80;

Open in new window


Surely you've already tried this, so mention why this didn't work + provide the exact error you're seeing.

Note: With no IP, default is always localhost (127.0.0.1) as @Dr. Klahn mentioned above.
Avatar of CEHJ

ASKER

OK. This is what my main web server is doing:

tcp6       0      0 :::443                  :::*                    LISTEN      600/apache2         
tcp6       0      0 :::80                   :::*                    LISTEN      600/apache2 

Open in new window


If it were listening on 127.0.0.1, I wouldn't be able to route to it and access it. It would act like a development server

Surely you've already tried this, so mention why this didn't work + provide the exact error you're seeing.
Indeed I did. I found netstat's output to have not changed in any way. I'll try it again to confirm I haven't lost the plot
CONFIRMED. I should perhaps say that this could be complicated by the fact that docker is involved. There again, that could be irrelevant. I don't know
The config file you attached has no IP, so localhost (127.0.0.1) is the correct (default) IP which will be used.

You must specify a specific (different) IP, else NGINX will always listen on localhost.
Avatar of CEHJ

ASKER

You must specify a specific (different) IP, else NGINX will always listen on localhost.
If it's the 'listen' directive, specifying 0.0.0.0:80 doesn't help. I wonder if it could be soemthing perhaps with line 30…
?
Avatar of CEHJ

ASKER

    upstream app {
        server 192.168.2.194:8080;
    }

    server {
        listen 192.168.2.194:80;

Open in new window


is my latest try. Still stubbornly listening on 127.0.0.1
Avatar of CEHJ

ASKER

Probably have to close this folks. There's an unholy configuration network between docker, rails and nginx. Probably only the authors are likely to know about this
With no IP adress nginx listens to 0.0.0.0  aka the ANY address.
if a webserver is bound to 127.0.0.1 then there (in most cases) is a VERY good reason to do so. f.e. there is some frontend processor acitve (another webserver as reverse proxy, haproxy or some load balancing tool... on the same host, that occupies the public addresses.

In most cases only ONE server can bind to an IP address. All other services will not bind to it.
0.0.0.0 listens on all addresses landing to that system.

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial