如何设置nginx:只允许域名访问,不允许IP访问

在nginx的所有server配置之前,增加:

server {
    listen 80 default_server;
    listen 443 ssl default_server;
    server_name _;
    return 403;
}

检查配置,重启即可:

nginx -t
nginx -s reload

Leave a Reply

Your email address will not be published. Required fields are marked *