Php

子目錄 nginx 中的 Symfony2 應用程序

  • December 1, 2011

我正在嘗試在我們伺服器的子目錄中設置一個 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;
       }
   }

}

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

找到了解決方案,也許它可以幫助其他人

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

}

引用自:https://serverfault.com/questions/334517