【发布时间】:2018-10-20 04:25:16
【问题描述】:
如标题描述,当我请求“http://example.com/test/poster/”时,我想获取真实文件“/home/vagrant/example/resouces/views/posters.html”。
这是我的 nginx 配置:
server_name example.com;
root /home/vagrant/example/public;
index index.html;
location / {
return 404;
}
location ~ ^/test/poster/?$ {
default_type text/html;
index posters.html;
alias /home/vagrant/example/resouces/views/;
}
但是当我发出请求时,我得到一个 404 响应。我搜索 nginx 错误日志,我得到以下信息:
2018/10/20 11:54:41 [debug] 4690#4690: *180 http script copy: "/home/vagrant/example/resouces/views/"
2018/10/20 11:54:41 [debug] 4690#4690: *180 open index "/home/vagrant/example/resouces/views/posters.html"
2018/10/20 11:54:41 [debug] 4690#4690: *180 internal redirect: "/test/poster/posters.html?"
2018/10/20 11:54:41 [debug] 4690#4690: *180 rewrite phase: 1
这是我的问题,当打开索引时,它找到了文件,为什么它会进行内部重定向?
我终于通过使用 try_files 解决了它,我只是想知道为什么当我在一个位置块中使用带有索引的别名时它不起作用。谢谢!
【问题讨论】:
标签: nginx