此配置部分适用于httpdocs / index.php处理的单个php项目:
location / {
root /srv/www/trunk/httpdocs;
index index.php;
# if file exists return it right away
if (-f $request_filename) {
break;
}
# rwrite params
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php$1 last;
break;
}
}
# if the request starts with our frontcontroller, pass it on to fastcgi
location ~ ^/index.php {
root /srv/www/trunk/httpdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /srv/www/trunk/httpdocs$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
所以我想要的是多个子项目。
mydomain.org/branch_r19999 =>映射到/my/root/branch_r19999/httpdocs/index.php mydomain.org/branch_r2909 =>映射到/ my / root / branch_r2909 /httpdocs/index.php
肯定用param重写: mydomain.org/branch_r19999/myparam1/myparam2 =>映射到/ my / root / branch_r19999 /httpdocs/index.php
我试着用它:
root /srv/www/branches;
location / {
if (-f $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$/(.+)$ /index.php$2 last;
break;
}
try_files $uri /index.php$request_uri;
}
location ~* "/(branch_r[0-9]+)" {
alias /srv/www/branches/$1/httpdocs;
#Serve static files directly.... but how? This doesn't work
if ($request_filename ~* \.(gif|html|jpe?g|png|ico|js|css|flv|swf|pdf|xml)$ ) {
break;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /srv/www/branches/$1/httpdocs/index.php;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
我不想在配置中静态配置子项目,这没有问题。
有没有像这样的配置?
答案 0 :(得分:0)
我认为问题是正则表达式变得贪婪并捕获整个URL,尝试将其限制为更精确
server {
index index.php;
root /srv/www/trunk/httpdocs;
location / {
try_files $uri /index.php$request_uri;
}
location ~* "/(branch_r[0-9]+)" {
alias /my/root/$1/httpdocs/;
}
location /index.php {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}