我的Nginx配置有问题.我有2台服务器,一台使用Nginx,另一台使用symfony3中的webApp.
这是我的配置:
location /portal/mysite/ {
set $frontRoot /srv/data/apps/mysite-portal-stag/current/web;
set $sfApp app.PHP; # Change to app.PHP for prod or app_dev.PHP for dev
root /srv/data/apps/mysite-portal-stag/current/web;
rewrite ^/portal/mysite/(.*)$/$1 break;
try_files $uri @sfFront;
}
location @sfFront {
root /srv/data/apps/mysite-portal-stag/current/web;
fastcgi_pass myserver:myport;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $frontRoot/$sfApp;
fastcgi_param SCRIPT_NAME /portal/mysite/$sfApp;
}
webSite适用于所有PHP脚本,但所有资产(静态文件)都是损坏的文件.我不太了解Nginx如何工作以指示什么是静态文件并“告诉”我的代理他们不是脚本.
> http://nginx.org/r/try_files
Checks the existence of files in the specified order and uses the first found file for request processing; the processing is performed in the current context. The path to a file is constructed from the file parameter according to the root and alias directives. It is possible to check directory’s existence by specifying a slash at the end of a name,e.g. “$uri/”. If none of the files were found,an internal redirect to the uri specified in the last parameter is made.
请注意,虽然您已经在使用try_files,但似乎您的路径处理可能不符合规范.
至于你自己的答案,使用临时解决方案,there’s nothing wrong with using a rewrite or two,但是说,看起来你会从别名指令中受益.
Defines a replacement for the specified location.
但是,你从未解释过为什么要提供/ tmp中的东西.请注意,/ tmp通常由某些cron
脚本自动清除,例如,在OpenBSD上,/etc/daily
脚本将自动清除find
并删除大于7天的文件(on a daily
basis,顾名思义).
总之,您应该首先弄清楚文件系统的Web视图和文件系统之间的适当映射是什么.
随后,如果找到前缀,则只需为资产使用单独的位置以及别名.
否则,找出try_files按预期工作的路径.