Nginx重写目录到Symfony App,但删除主机目录

我有一个虚拟机,上面有几个开发应用程序。 基本的Web目录如下所示:

/var/web/subdoms/: index.php MyApp/ SomeOtherApp/ 

我有我的Nginx的configuration文件,指定根作为/ var / web / subdoms,例如:

 http://myserver/ -> /var/web/subdoms/index.php. 

在MyApp子目录中,是一个Symfony2项目。 SomeOtherApp目录是一个通用的perl-cgi应用程序

 http://myserver/SomeOtherApp -> /var/web/subdoms/SomeOtherApp/index.pl 

对MyApp的请求需要redirect到以下子目录:

 http://myserver/MyApp/ -> /var/web/subdoms/MyApp/symfony/web/ 

从那里,请求需要重写,以便请求被传递到'app.php'ala:

 http://myserver/MyApp/ -> /var/web/subdoms/MyApp/symfony/web/app.php http://myserver/MyApp/hello/you -> /var/web/subdoms/MyApp/symfony/web/app.php/hello/you 

当我设置我的根:/ var / web / subdoms / MyApp / symfony / web /,并通过遵循symfony文档中的示例来请求sans'MyApp'时,我可以完成此操作。 然而,当我尝试嵌套应用程序的一个目录(以便我的服务器可以在同一个域上服务多个应用程序,而不是由symfony应用程序支配),“MyApp”部分被添加到URL ala:

 http://myserver.com/MyApp/hello/you -> /var/web/subdoms/MyApp/symfony/web/app.php/MyApp/hello/you 

然后symfony抱怨说找不到路线“MyApp / hello / you”。 我可以通过在我所有的symfony路线上加上“MyApp”来解决这个问题,但是这让人感觉很笨拙。 我宁愿通过Nginxfind一个方法来转发urlsans目录到Symfony。

如果有帮助,这是我目前的nginxconfiguration(删除了其他应用程序):

 server { listen 80; server_name myserver; root /var/web/subdoms; error_log /var/log/nginx/rr_error.log; access_log /var/log/nginx/rr_access.log; location /MyApp/ { rewrite ^/MyApp/(.*)$ /MyApp/symfony/web/app_dev.php/$1 last; } #was the way to redirect requests to app_dev.php when MyApp/Symfony/web was root location @rewriteRR { rewrite ^(.*)$ /app_dev.php/$1 last; } location ~ \.php(/|$) { include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param HTTPS on; fastcgi_pass 127.0.0.1:9000; } location ~ /\.ht { deny all; } } 

作为结束语,我认识到最好使用子域来分隔应用程序(或多个域),但是如前所述,这是一个开发服务器。 将其分割成子域,不同的主机等,对于它的成本来说太昂贵了。 由于成本原因(SSL证书/托pipe费用),我需要将其保留在同一主机/域上,同时避免自签名证书(因为开发时,应用程序被其他人用在不经意的环境中,自签名的错误刺激他们)。