-1

I would like to create multiple subdomains using nginx from 1 IP address. So it would be something like this:

http://demo1.192.168.0.27
http://demo2.192.168.0.27

Someone already asked this question in the past.
nginx - two subdomain configuration I tried the same way but I'm not able to do it.

Here's my code:

events {
}

http {
   server {
      server_name demo1.192.167.0.27;
      root /data/sites/demo1;
      index index.html;

      location / {
         try_files $uri $uri/ /404.html;
      }  
   }

   server {
      server_name demo2.192.167.0.27;
      root /data/sites/demo2;
      index index.html;

      location / {
         try_files $uri $uri/ /404.html;
      }  
   }

}

When I go to

http://demo1.192.168.0.27
http://demo2.192.168.0.27

It said, This site can’t be reached

Not sure why it's not working for me.

user1736786
  • 139
  • 1
  • 4
  • 11

2 Answers2

1

You can't create subdomains on IP addresses.

In the answer you're referencing, they're using domain names, like this:

server_name sub1.example.com;
server_name sub2.example.com;

That's why it works, as opposed to what you have, with IP addresses:

server_name demo1.192.167.0.27;
server_name demo2.192.167.0.27;
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
0

Your domain names are not public. You can resolve to a DNS provider to make them public.

You also can add xxx.xxx.xxx.xxx demo1.192.168.0.27 to your local hosts file C:\Windows\System32\drivers\etc\hosts, to make them avaliable to your local machine.

LF00
  • 27,015
  • 29
  • 156
  • 295