nginx配置只用ip或域名访问时都指向到同一个页面

假设服务器ip 12.34.12.12 ; 想要配置访问http://12.34.12.12时重定向访问/dir/null.html文件,配置如下(同样适用于仅用域名访问, 只不过server_name 处 localhost改为你的域名)

  server {
        listen       80;
        server_name  localhost;
        root /home/wwwroot/;

        location / {
           root /home/wwwroot/;
           index index.html;
           rewrite ^/$  /dir/null.html break;  //这句是关键, 重定向到/dir/null.html页面中
        }

}

猜你喜欢

转载自blog.csdn.net/weixin_37281289/article/details/103473394