Having multiple Symfony2 apps on same domain

B.R. reallfqq-nginx at yahoo.fr
Sun Dec 28 23:03:12 UTC 2014


You are using the same named location as the fallback of the try_files
directive, although you are dealing with three different paths.

Why do not you use one fallback named location per app location, each
rewriting to the correct path?
---
*B. R.*

On Sun, Dec 28, 2014 at 10:16 PM, Naji Astier <naji.demolitionman at gmail.com>
wrote:

> Le 28/12/2014 20:30, Steve Holdoway a écrit :
>
>  On Sat, 2014-12-27 at 05:52 -0500, Claros wrote:
>>
>>> Hello everybody !
>>>
>>> I just switched from Apache2 to Nginx and I met some issues having the
>>> same
>>> configuration. What I want to do is having multiple Symfony2 apps on the
>>> same domain name. Each app will have a subdirectory and a main app will
>>> be
>>> on the domain name itself. For instance :
>>> http://mydomain/               -> main app
>>> http://mydomain/subdir1   -> another app
>>> http://mydomain/subdir2   -> yet another app
>>> One of Symfony2 feature is to have only three php files to be executed,
>>> and
>>> all the URL are rewritten to those files. You can found basic
>>> configuration
>>> for Symfony2 at this address if you need more information :
>>> http://wiki.nginx.org/Symfony
>>> Now after many hours of configuration, with the help of debug logs, I
>>> almost
>>> did it. This is my current configuration :
>>>
>>> server {
>>>      listen   80;
>>>      server_name mydomain;
>>>      root /server/www/main-app/web;
>>>
>>>      location @rewriteapp {
>>>          rewrite ^(.*)$ /app.php/$1 last;
>>>      }
>>>
>>>      location /subdir1/ {
>>>          # alias /server/www/other-app1/web;
>>>          set $root "/server/www/other-app1/web";
>>>          # try to serve file directly, fallback to app.php
>>>          try_files $uri @rewriteapp;
>>>      }
>>>
>>>      location / {
>>>          index app.php;
>>>          set $root "/server/www/main-app/web";
>>>          # try to serve file directly, fallback to app.php
>>>          try_files $uri @rewriteapp;
>>>      }
>>>
>>>      # PROD
>>>      location ~ ^/app\.php(/|$) {
>>>          fastcgi_pass unix:/var/run/php5-fpm.sock;
>>>          fastcgi_split_path_info ^(.+\.php)(/.*)$;
>>>
>>>          include fastcgi_params;
>>>          fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
>>>          fastcgi_param SCRIPT_NAME $fastcgi_script_name;
>>>          fastcgi_param PATH_INFO $fastcgi_path_info;
>>>      }
>>> }
>>>
>>> Why did I create a variable "$root" ? Because when I was using the root
>>> (or
>>> alias) directive in a location block and the variable $document_root, I
>>> found out that this variable has as final value (in the location app.php)
>>> the first root directive in the server or the default root location.
>>> With this configuration, it almost work. The main app works and the
>>> subdirectories are correctly sent to their directory. The last problem is
>>> that the URI processed by the file app.php also contains the
>>> subdirectory in
>>> it, so the others apps send 404 for all the URL. I tried to fix that by
>>> changing "REQUEST_URI" parameter, but with that the app.php generate
>>> wrong
>>> URL without the subdirectory.
>>>
>>> So is their a way to achieve this configuration ? Thanks you !
>>>
>>> Posted at Nginx Forum: http://forum.nginx.org/read.
>>> php?2,255806,255806#msg-255806
>>>
>> Try using a map to set the $root...
>>
>> Steve
>>
>>  Ok I did not know the map system, it is interesting. But it is only
> simplifying my configuration, not solving the problem.
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20141229/66652a29/attachment.html>


More information about the nginx mailing list