我正在尝试在我们服务器的子目录中设置一个 symfony2 应用程序
Web服务器:nginx 1.1.6 + php fpm 操作系统:gentoo
我的目标是让应用程序从子目录运行
子域名.xy.域名.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;
}
}