假设服务器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页面中
}
}