在nginx重写规则中排除index.html

时间:2014-07-04 04:50:10

标签: nginx

我有一个网站,我以https模式呈现,我在default.conf中编写了重写规则,如下所示:

listen       80;
server_name  hostname.com;
rewrite      ^ https://$server_name$request_uri? permanent;

但是,我需要从重写中排除index.html或/。如何编写规则以排除重写index.html/

1 个答案:

答案 0 :(得分:0)

我认为没有理由这样做,但是这里是从重写中排除//index.html的示例。此外,我已将rewrite更改为更高效的return指令。

listen 80;
server_name example.com;
root /path/to/root/dir;

# exclude / from rewrite
location = / {
    index index.html;
}

# exclude /index.html from rewrite
location = /index.html {
}

location / {
    return 301 https://$host$request_uri;
}