Vinay
Vinay

Reputation: 962

Binding IP address to Angular site hosted on nginx

I have successfully hosted an angular website on nginx and my nginx.conf file looks like below,

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   C:/Angular-Project/angular2-trial/dist;
            index  index.html;
        }
        }

But I want to bind an IP address(say 10.194.31.21:8000) so that the site can be accessed anywhere in the Internal network (unlike localhost).

I tried to modify listen to 10.194.31.21:8000, but this doesn't seem to work.

What is the correct way to achieve this?

Upvotes: 3

Views: 1497

Answers (2)

Vinay
Vinay

Reputation: 962

I tried Reload and restarting nginx service to enable the new configuration, but in vain.

Rebooting my windows pc with the same config file, did the trick.

Upvotes: 1

Julien TASSIN
Julien TASSIN

Reputation: 5212

You need to change both server_name and listen to ensure that. The following conf will respond to 10.194.31.21:8000

server {
  listen       8000;
  server_name  10.194.31.21;

  #charset koi8-r;

  #access_log  logs/host.access.log  main;

  location / {
    root   C:/Angular-Project/angular2-trial/dist;
    index  index.html;
  }
}

If you don't care about the hostname, you can also set server_name to _ catch all server names :

server {
  listen       8000;
  server_name  _;

  #charset koi8-r;

  #access_log  logs/host.access.log  main;

  location / {
    root   C:/Angular-Project/angular2-trial/dist;
    index  index.html;
  }
}

The listen is for the port and the server_name for the server name send by the browser. With the second solution you catch everything to your angularjs app (the drawback is that you can not host a other application with this nginx on this port).

Upvotes: 0

Related Questions