Home  >  Q&A  >  body text

Nginx prohibits access from other domain names

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梦2712 days ago430

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:30:45

    You configure the default domain name to return 403:

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

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

    reply
    0
  • Cancelreply