Ruby on rails 让nginx提供特定目录中的所有文件
我想让nginx在我的Rails应用程序中提供/public/system/articles/images中的所有图像。我试过了 位置/系统{ 允许一切; } 当我把它放在我的_site.com/public/system/picture.png中时,会返回Rails 404页面(与nginx 404页面相反,或者是我真正想要的图像) 这是我当前的conf文件:Ruby on rails 让nginx提供特定目录中的所有文件,ruby-on-rails,nginx,Ruby On Rails,Nginx,我想让nginx在我的Rails应用程序中提供/public/system/articles/images中的所有图像。我试过了 位置/系统{ 允许一切; } 当我把它放在我的_site.com/public/system/picture.png中时,会返回Rails 404页面(与nginx 404页面相反,或者是我真正想要的图像) 这是我当前的conf文件: upstream varnish { server localhost:6081; } server { liste
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;
}
}
似乎我不需要对nginx conf文件做任何事情 当尝试访问
/public
目录下的内容时,您不会将/public
放在正在调用的URL中
因此,我应该把
my_site.com/public/system/picture.png
放在my_site.com/system/picture.png
中,而不是放在regex中。我刚试过这个<代码>文件=“/system/articles/images/bar.png”;file=~/\(ico | css | js | gif | jpe | g | png)\?[0-9]+?$/=>nil如果禁用该位置指令,则会出现相同的错误。但您希望使用该指令来为静态图像提供服务吗?如果是这样的话,你需要修复正则表达式,而不是禁用它。啊,抱歉,我说得太清楚了!在/system中提供图像的指令是location/system{}
,稍微向下一点。根据nginx命令指令的方式,应该在regex之前使用AFAIK,不是吗?此外,如果我有一些未被正则表达式捕获的内容,例如/public/system/test_file.txt,我仍然会遇到同样的问题。