包含zf2 / php文件的多个子目录的nginxconfiguration不起作用

我的根结构看起来像这样

/ root / / root / projectA / … / root / projectB / … / root / projectC / …

在我的nginx文件中为每个子目录configuration一个额外的位置块之前, 这些位置“块”看起来像这样:

server { listen 80; listen [::]:80; root /usr/share/root/projectA/public/; index index.php index.html index.cgi; server_name www.test.de; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } 

}

这样,我的ZF2应用程序驻留在/ root / projectA按预期工作。 但随着子项目数量的增长,我想使用一个通用的正则expression式解决scheme,所以我不必一遍又一遍地为每个子目录编写相同的块。

所以这是我的做法,使这些项目下的子域vendor.test.de与vendor.test.de/projectA / …下提供的每个项目:

 server { listen 80; listen [::]:80; root /usr/share/root/; index index.php index.html index.cgi; server_name vendor.test.de; rewrite_log on; error_log /var/log/nginx/debug.log debug; location ~ ^/(.+)/ { root /usr/share/root/$1/public; try_files $uri $uri/ $1/public/index.php?$args; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } } 

}

但我得到的只是一个404,它只是不工作。 我debugging了一些日志文件,它似乎performance出奇怪的尝试获取/usr/share/root/index.php而不是/usr/share/root/projectA/public/index.php即使他find了正确的位置第一…

任何想法呢?

提前致谢!

在你的location你需要使用alias而不是root

  alias /usr/share/root/$1/public/;