【发布时间】:2014-08-30 15:40:55
【问题描述】:
类似于this question,我遇到了 nginx 重写的问题。
这是我的 nginx 配置文件:
server {
listen 80;
server_name myserver.com www.myserver.com;
index index.html;
root /var/www/myserver.com/site/;
location /blog {
alias /var/www/myserver.com/blog/output/;
break;
}
location / {
autoindex on;
try_files $uri $uri/ @htmlext;
}
location /.hg {
deny all;
return 404;
}
location ~ \.html$ {
try_files $uri =404;
}
location @htmlext {
rewrite ^(.*)$ $1.html last;
}
error_page 500 502 503 504 /media/50x.html;
}
看起来问题出在location ~ \.html 规则上。当我删除它时,它工作正常。
我尝试了多种方法,例如:
- 将
location /blog指令移到顶部(它曾经位于底部) - 按照链接问题的建议输入
break;。
到目前为止,似乎没有任何效果。在当前配置中,我得到一个 404,这也是 access.log 中显示的内容。
如何使重写工作隐藏.html 扩展,同时让我提供blog/output/ 内容?
【问题讨论】: