将通过 IP 地址访问的请求拦截或重定向

拦截到 404

#
# The default server
#

server {
    listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  _;
    #root         /usr/share/nginx/html;
    return 404; 

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

关键配置:return 404;

重定向到指定页面

#
# The default server
#

server {
    listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  _;
    #root         /usr/share/nginx/html;
    rewrite ^ https://yoursite.com$request_uri?;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

关键配置:rewrite ^ https://yoursite.com$request_uri?;

0 条评论

昵称

沙发空缺中,还不快抢~