【发布时间】:2015-09-28 23:45:44
【问题描述】:
我想让 nginx 在我的 Rails 应用程序中提供 /public/system/articles/images 中的所有图像。我试过了 位置/系统{ 允许所有; }
当我放入 my_site.com/public/system/picture.png 时,它返回 Rails 404 页面(与 nginx 404 页面相反,或者我真正想要的图像)。
这是我当前的 conf 文件:
upstream varnish {
server localhost:6081;
}
server {
listen 80;
server_name my_site.com;
location ~* \.(ico|css|js|gif|jpe?g|png)\?[0-9]+?$ {
expires max;
break;
}
root /home/my_site/my_site/current/public;
location /system {
allow all;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-AI-App "my_site";
proxy_pass http://varnish;
}
#root /home/my_site/my_site/current/public;
location / {
# all IP addresses are listed here:
allow all;
try_files $uri @app;
}
}
【问题讨论】:
-
可能是你的正则表达式有问题。我刚试过这个。
file = "/system/articles/images/bar.png"; file =~ /\.(ico|css|js|gif|jpe?g|png)\?[0-9]+?$/ => nil -
如果我禁用该位置指令,我会得到同样的错误。
-
但是,这是您想要使用它来提供静态图像的指令吗?如果是这样,您将需要修复正则表达式而不是禁用它。
-
啊,对不起,我说得像泥巴一样!在 /system 中提供图像的指令是
location /system { },稍微往下一点。根据nginx命令指令的方式,应该在正则表达式之前使用AFAIK,不是吗? nginx.org/en/docs/http/request_processing.html -
另外,如果我有一些未被该正则表达式捕获的东西,例如 /public/system/test_file.txt,我仍然会遇到同样的问题。
标签: ruby-on-rails nginx