意外的行为与嵌套的位置,别名和php-fpm上游

晚上好,

〜我想做什么〜

我需要一个默认的位置块匹配任何东西,我猜,这个块有它自己的根目录。 它必须提供任何静态文件,并解释其文档根或子文件夹内的任何PHP文件。 (我设置它,它接缝工作正常)

这里是我需要一些帮助:(

在这个相同的服务器块里面,我想主持一个php symphony应用程序,当它碰到mydomain.foo/panel/区域。 所以我添加了一个^~ /panel/ location(uri以/ panel /开头)

我的问题是,try_files不像我所期望的(内部redirect到最后一个嵌套位置,以防uri不匹配嵌套位置)。 看下面的代码注释。

〜我的configuration是…〜

 upstream phpfcgi { server unix:/var/run/php5-fpm.sock; } server { listen 80; server_name domain.tld; ## Default locations location / { root /home/me/sites/default/www; index index.php; location ~ \.php$ { include fastcgi.conf; fastcgi_pass phpfcgi; } location ~ /(.+) { try_files $uri $1 =404; } } ## panel area location ^~ /panel/ { # Public files are located in sf/web sub-directory alias /home/me/sites/sf/web/; # Since uri starts with '/panel/', I expect NGINX to execute try_files as a last resort. # if nested location do not match, and uri is not an existing file, # shouldn't nginx do an internal redirect with the 2nd try_files argument # and finally hit the nested location (triggering fastcgi_pass) ? # But try_files is ignored and nginx falls back to "/" location above instead. try_files $uri /panel/app_dev.php$is_args$args; # FastCGIpass to upstream location ~ (app_dev|config)\.php(/|$) { try_files $fastcgi_script_name =404; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; include fastcgi.conf; fastcgi_pass phpfcgi; } } # Custom errors error_page 403 404 =404 @null; error_page 324 500 502 503 504 =500 @null; location @null { root /home/me/sites/_; rewrite ^.+$ /$status.html break; try_files $uri 444; } } 

如果我的configuration太笨拙,那我该如何满足我的要求? (具有文档根目录的默认位置,以及服务于我的php应用程序的特殊区域,在同一个服务器上)?

NGINX文档越来越好,但在请求处理stream程中仍然存在一些我不明白的地方。

任何解决scheme/build议/改进?

谢谢:)

你正在使用嵌套的位置块。 我没有用过它们,因为我不太了解它们,但它们似乎增加了复杂性。 尝试使用未嵌套的位置块。 你的configuration看起来和我见过的其他configuration完全不一样,但是我的nginx经验是有限的。

我有一个在这个问题上我的configuration的例子。

Nginx HHVM WordPress问题与PHP执行在一个中间子目录

这里有一些最好的做法。

这个问题还包括一个如何debugging这些东西的例子,通过添加标题并查看它们。 使事情更容易理解和debugging。 如果这就是我从答案中得到的一切,我认为这将是有价值的。