Nginx prohibits access from other domain names
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 17:28:45
0
1
455

My server is built using Nginx. Now there is a scenario as follows:

A.com的A记录指向a.b.c.d
B.com的A记录指向a.b.c.d

My Nginx settings

listen a.b.c.d:80 default;
server_name A.com;

Currently, when you visit B.com, my site will be opened by default, and the resources on the site can also be referenced correctly.

How to configure it so that B.com and other domain names cannot be accessed?

I understand that if you add a judgment if{}, you can return error codes for other domain names, but if there are multiple vhosts, it will be more troublesome to configure. Is there a more elegant and universal way?

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
淡淡烟草味

You configure the default domain name to return 403:

server {
  listen 80 default_server;
  location / {
    return 403;
  }
}

See: http://wiki.nginx.org/NginxVirtualHostExample

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template