Nginx在一个子目录中使用php


Nginx with php in one subdirectory

我有一个纯HTML的网站。现在我必须添加一个包含 PHP 文件的子目录(演示)。我在nginx.conf文件中设置了两个位置:

server {
    listen          80;
    server_name     mydomain.com;
    access_log      /mydomain.com/access.log;
    location / {
        root        /www;
        index       index.html index.htm;
    }
    location /demo {
        root        /www/demo;
        index       /demo/index.php;
    }                                                                                                                                                                                                       
    location ~ /demo/.*'.php$ {
        root        /www/demo;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;                                                                                                                                                                                                          
        fastcgi_param  SCRIPT_FILENAME  /www/demo$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /'.ht {
        deny         all;
    }
}

现在 mydomain.com 工作正常,但是当我尝试访问 mydomain.com/demo/时,它一直在抱怨

No input file specified.

这个脚本有什么问题?我想某些路径没有像fastcgi_index那样正确设置:它应该是/demo/index.php?我尝试了不同的组合,但没有一种有效。任何帮助将不胜感激!

您的fastcgi_param很可能应该/www$fastcgi_script_name,因为变量是完整的 URI 请求。源。