2

I'm trying to setup a symfony2 app in a subdirectory of our Server

Webserver: nginx 1.1.6 + php fpm OS: gentoo

my target is to get the app working from a subdirectory

subdomain.xy.domain.tld/tool

my nginx config looks like that

server  {

    listen          80;
    server_name     subdomain.xy.domain.tld;

    error_log       /var/log/nginx/subdomain.xy.error.log info;
    access_log      /var/log/nginx/subdomain.xy.access.log main;


    location /tool {

        root /var/www/vhosts/subdomain.xy/tool/web;

        index app.php;

        location ~ \.php($|/) {
            include fastcgi_params;

            set $script $uri;
            set $path_info "";

            if ($uri ~ "^(.+\.php)($|/)") {
                set $script $1;
            }

            if ($uri ~ "^(.+\.php)(/.+)") {
                set $script $1;
                set $path_info $2;
            }

            fastcgi_param SCRIPT_FILENAME /var/www/vhosts/subdomain.xy/tool/web$fastcgi_script_name;
            #fastcgi_intercept_errors on;
            fastcgi_pass 127.0.0.1:9000;

            fastcgi_param SCRIPT_NAME $script;
            fastcgi_param PATH_INFO $path_info;
        }
    }

}

I have really no clue how to do this... I've searched the web for hours and tried dozens of different configs but nothing worked. I hope someone has an idea =)

Andy Smith
  • 1,798
  • 13
  • 15
Frido
  • 73
  • 1
  • 7

1 Answers1

4

Found the solution maybe it helps somebody else

server {
listen          80;
server_name     domain.xy;

error_log       /var/log/nginx/domain.xy.error.log info;
access_log      /var/log/nginx/domain.xy.access.log main;

root /var/www/vhosts/domain.xy;

location /tool {
    alias /var/www/vhosts/domain.xy/tool/web;
    index app.php;
        if (-f $request_filename) {
             break;
        }
        rewrite ^(.*)$ /tool/app.php last;
}

location ~ /tool/(.+)\.php(/|$) {
    set $script $uri;

        if ($uri ~ "/tool/(.+\.php)(/|$)") {
            set $script $1;
    }

    fastcgi_pass backend;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param  SCRIPT_FILENAME  $document_root/tool/web/$script;
}

}
Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
Frido
  • 73
  • 1
  • 7
  • Great ! Could someone explain me how this config file will process `/tool/some/page` ? I don't get how php would be aware of the full page's path since the rewrite rule is not appending anything after app.php (like would `/tool/app.php$1` do). – Stphane Jan 17 '16 at 16:52
  • You can access the request uri via `$SERVER['REQUEST_URI']` – Frido Jan 18 '16 at 12:55