我有一个与wordpress一起运行的Symfony2应用程序-mysite.com/blog路由到我的/ var / www / mysite / wordpress /目录,其他所有路由到/ var / www / mysite / symfony:
server {
listen 80;
server_name mysite.com
location / {
try_files $uri /app.PHP$is_args$args;
}
location ~ ^/app\.PHP(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.PHP)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
internal;
}
location /blog {
root /var/www/mysite/wordpress;
rewrite ^/blog/(.+)$/$1 break;
try_files $uri $uri/ /blog/index.PHP?q=$uri&$args;
index index.PHP;
location ~ \.PHP {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(?:\/blog)(.+\.PHP)(.*);
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
一切正常,除了wordpress管理员(mysite.com/blog/wp-admin/)给我一个404错误.访问mysite.com/blog/wp-admin/index.PHP可以按预期工作,因此索引index.PHP行似乎不起作用.这里可能是什么问题?
最佳答案
您应该使用别名而不是root指令:
location ^~ /blog {
alias /var/www/mysite/wordpress;
index index.PHP;
try_files $uri $uri/ /blog/index.PHP?q=$uri&$args;
location ~ \.PHP${
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(?:\/blog)(.+\.PHP)(.*);
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}