0

I have a problem with my nginx configuration.

On most of pages and google search entries i found things like "nginx and symfony2" or "nginx and symfony2 in subdirectory". But i not find some thing about this configuration:

  1. Normal php file projects (path like localhost/project -> /srv/www/project/index.php / ruled per index)
  2. Symfony2 projects (path like localhost/symfony2 -> /srv/www/symfony2/web/app.php (default) and manually app_dev.php / unknown!?)

Current configuration

server
{
    listen   80;
    listen   [::]:80 default_server ipv6only=on;

    root /srv/www;
    index index.php index.html index.htm app.php app_dev.php;
    try_files $uri $uri/ index.php @rewriteapp /index.php;

    server_name localhost;

    location ~ ^\/symfony2
    {
        #rewrite ^\/symfony2(.*)$ /symfony2/web$1 last;
        #root /srv/www/symfony2/web;
        alias /srv/www/symfony2/web;
    }

    location @rewriteapp
    {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ \.php(/|$)
    {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Thank's in advance for each tip!

1 Answer 1

0

This configuration should help.

server {
    listen   80;
    listen   [::]:80 default_server ipv6only=on;

    root /srv/www;
    index index.php index.html index.htm app.php app_dev.php;

    server_name localhost;

    location / {
        try_files $uri $uri/ /app.php /index.php;
        location ~ .*\.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

    location /symfony2 {
        alias /srv/www/symfony2/web;

        location ~ .*\.php(/|$) {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

        location ~ /symfony2(?<path>.*)$ {
            root /srv/www/symfony2/web; 
            try_files $path $path/ /app.php$path;
        }
    }
}
Sign up to request clarification or add additional context in comments.

8 Comments

2013/12/06 14:30:24 [error] 5755#0: *189 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::1, server: localhost, request: "GET /symfony2/web/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost" ::1 - - [06/Dec/2013:14:30:24 +0100] "GET /symfony2/web/ HTTP/1.1" 404 47 "-" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" ::1 - - [06/Dec/2013:14:30:34 +0100] "-" 400 0 "-" "-"
I changed it a little (/symphony2/app.php replaced with regex), please try it now
Works: http://localhost/symfony2/app_dev.php/en/test/index Works: http://localhost/symfony2/app.php/en/test/index DOESNT works: http://localhost/symfony2/en/test/index Works: http://localhost Works: http://localhost/index.php
DOESNT works: localhost/symfony2/en/test/index - should it work? if so what script should handle it?
Thats the only thing which is wrong. Projects should completely rewrited to web directory: localhost/symfony2/en/test/index == /srv/www/symfony2/app.php/en/test/index Every thing is perfect. I can use normal projects and symfony2 projects ^^ But the "index" / default file is empty... It should be the app.php file :) Thank you!!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.