Avatar of CEHJ
CEHJ
Flag 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

Web Servers

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
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/
David Favor

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.
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
David Favor

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.
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…
?
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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
noci

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
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question