我遇到nginx配置问题(我使用apache)。我要重写,所以我配置了:
location = / {
root /var/www/domain.tld/public_html;
index index.php;
}
location / {
root /var/www/domain.tld/public_html;
index index.php;
if (!-f $request_filename) {
rewrite ^(.*)$ /index.php last;
break;
}
if (!-d $request_filename) {
rewrite ^(.*)$ /index.php last;
break;
}
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|wmv)$ {
access_log off;
expires 30d;
}
问题是我的静态文件位于/ css,/ img,/ js等目录中,但我还有一个php控制器,它为用户上传的文件提供服务,其结构为:domain.tld/media/image/NAME/EXTENSION
。这不起作用,因为它试图获取一个静态文件,但如果我选择domain.tld/media/image/NAME/EXTENSION/
(请注意最终的 / ),它可以正常工作。
我如何解决这个问题?
提前谢谢!
答案 0 :(得分:3)
您没有阅读文档,是吗? ;) 它列在来自Apache的用户常见的陷阱中。使用try_files指令,如下所述: http://wiki.nginx.org/Pitfalls#Check_IF_File_Exists