Nginx FastCGI 仅在子目录中?

Nginx FastCGI 仅在子目录中?

我有一个域,其中根由在 uWSGI 下运行的 python 应用程序提供服务。但是,我需要在子文件夹 /forum/ 上运行 PHP 论坛。我在apps-available配置文件中有以下内容:

location / { try_files $uri @oath; }
location @oath {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:3031;
}
location /forum/ {
    alias /home/drake/forum;
    index index.php;
}
location ~ /forum/(.*)\.php {
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
}

然而,example.com/forum/被发送到 uWSGI 应用程序,并且example.com/forum/index.php在交给 FastCGI 时,返回File not found.并记录以下内容error.log

2013/03/03 00:10:52 [error] 28102#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 93.96.158.230, server: example.com, request: "GET /forum/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com"

我究竟做错了什么?

答案1

您的/forum/(.*)\/.php块未设置适当的根目录,因此 PHP 找不到脚本。请尝试以下操作(替换您的两个论坛位置块):

location /forum {
    root /home/drake;
    index index.php;
    location ~ \.php(?|$) {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
    }
}

相关内容