Search code examples
nginxserveriplamp

How to connect to another IP using NGINX


I am wondering how to connect to a different IP in Nginx that is different from localhost.

00.000.00.00
root
123456

note (the IP address and password indicated above are not realand will be replaced will actual) Right now, this is what I have in Nginx config

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

Solution

  • By default nginx listens on all interfaces, that would be that listen 80; is equivalent to listen 0.0.0.0:80;. If you want nginx to listen only on localhost you should write listen 127.0.0.1:80; or listen localhost:80;, and if you want it to listen on some other interface you could do something like listen 152.168.0.30:80;.

    On the other hand using the line server_name localhost; you are only accepting request directed to localhost in this block, and no the ones directed to your other IP's. To accept this request you can add server_name localhost 152.168.0.30 www.myweb.com; like a list or you could exclude this config so that the host IP isn't a restriction to accept or not a request.

    For more information look in here.

    Hope it helps!