Symfony2 應用程式位於 nginx 子目錄中

Symfony2 應用程式位於 nginx 子目錄中

我正在嘗試在我們伺服器的子目錄中設定 symfony2 應用程式

網路伺服器:nginx 1.1.6 + php fpm 作業系統:gentoo

我的目標是讓應用程式從子目錄運行

subdomain.xy.domain.tld/工具

我的 nginx 設定看起來像這樣

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;
        }
    }

}

我真的不知道如何做到這一點...我在網上搜索了幾個小時並嘗試了數十種不同的配置,但沒有任何效果。我希望有人有想法=)

答案1

找到解決方案也許對其他人有幫助

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;
}

}

相關內容