This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Symfon2 + nginx setup, issue with redirect loop at front

Discuss installing Symfony 2 here

Symfon2 + nginx setup, issue with redirect loop at front

by lyambda71 » Mon Nov 10, 2014 5:45 am


I'm installing SF2 into the subdirectory (don't ask why, I have the same problem described below when working from the root dir).
Here's my nginx config from server block:

Code: Select all
listen 80;
autoindex on;
root /var/www/;

rewrite ^/project/app_dev\.php/?(.*)$ /project/$1 permanent;

location /project {
alias /var/www/;
index app_dev.php;
try_files $uri $uri/ @symfony;

location @symfony {
rewrite ^/project/(.*)$ /project/app_dev.php/$1 last;

location ~ ^/project/(.+)\.php(/|$) {
alias /var/www/;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^/project/(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME /project/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;

When trying to access:

Everything is fine, requests get routed to symfony and nothing is wrong about it...

But, when trying to access the app by it's domain or, in my case, subdir name directly: (with or without trailing slash - doesn't matter)

I get a redirect loop. Don't understand where from. Interesting, that in this case, if I choose to remove $uri/ (with slash) from try_files directive (which is inside location / {} block) - it starts working, but I don't know how these things in my config are connected together. Moreover, I actually NEED this $uri/ because I need a direct access to real folders with yet unknown names (e.g. user-created folders with php apps), bypassing symfony.

Please, help me understand what's wrong with my config and how can I leave try_files directive untouched and just set up everything working fine.
Junior Member
Posts: 1
Joined: Mon Nov 10, 2014 5:38 am