您的位置:首页 > 运维架构 > Nginx

nginx配置 首页不显示 index.html首页是显示域名

2016-08-09 14:38 585 查看
原状况如下:

访问:www.test.com 敲回车后浏览器中自动跳转致: www.test.com/index.html

公司新需求如下:

访问:www.test.com 敲回车后浏览器中url不变,仍显示www.test.com,但是能访问到index.html页面。

配置如下:

#以下为负载均衡设置,与题目无关

upstream index {

server 123.159.147.369:7069  weight=20 max_fails=2 fail_timeout=30s;

ip_hash;

}

#以下为server站点设置

server {

listen       80;

server_name www.test.com;

root   /home/wwwroot/index;

location / {

index  index.html index.htm;

proxy_set_header HOST   $host;

proxy_set_header X-Real-IP      $remote_addr;

proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;

#此if为判断访问/目录有,匹配到该if,跳转到index配置项,即访问到index.html。

if ( !-e $request_filename ) {

proxy_pass      http://index; 
}

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;

}

#静态文件请求location设置,与题目无关

location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

root /home/wwwroot/index;

expires 30d;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: