我有一个设置了PHP-FPM的Nginx HTTP服务器,几乎一切正常。我希望能够转到path/to/file
,它会给我index.php?url=path/to/file
。但是,它会下载实际的PHP,它不会在浏览器中执行它。我不确定是什么导致了这一点。
Nginx配置:
server {
listen 80;
server_name sandbox.domain.tld;
access_log /path/to/domain/log/sandbox.access.log;
error_log /path/to/domain/log/sandbox.error.log;
location / {
root /path/to/sandbox;
index index.php;
if (!-e $request_filename) {
rewrite ^/beta/(.+)$ /beta/index.php?url=$1 break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /path/to/sandbox$fastcgi_script_name;
}
答案 0 :(得分:19)
尝试更改
rewrite ^/beta/(.+)$ /beta/index.php?url=$1 break;
到
rewrite ^/beta/(.+)$ /beta/index.php?url=$1 last; break;
哪个应该让nginx重新读取URI并相应地处理它。