Anton
Anton

Reputation: 1502

Nginx configuration for hosting server under ip and port instead of domain name

Currently my nginx sites-avaliable is set up that i host under specific domain name.

server {
      listen 80;
      server_name mydomain.com;
      access_log off;
      error_log off;
      location / {
      proxy_pass http://127.0.0.1:3011;
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_max_temp_file_size 0;
      client_max_body_size 10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout 90;
      proxy_send_timeout 90;
      proxy_read_timeout 90;
      proxy_buffer_size 4k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;
   }
}

How i can change a server_name if i want to run Server on 127.0.0.0:3009 and externally if i hit 79.180.12.54:3009 it should get to website.

Basically change server_name to 79.180.12.54:3009

Upvotes: 0

Views: 894

Answers (1)

Shawn C.
Shawn C.

Reputation: 6841

server_name can be an IP

If someone makes a request using an IP address instead of a server name, the “Host” request header field will contain the IP address and the request can be handled using the IP address as the server name:

server_name  example.org
             www.example.org
             ""
             192.168.1.1
             ;

Upvotes: 1

Related Questions