【问题标题】:Nginx with php in one subdirectoryNginx 和 php 在一个子目录中
【发布时间】:2012-08-16 15:11:18
【问题描述】:

我有一个纯 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 吗?我尝试了不同的组合,但没有一个有效。任何帮助将不胜感激!

【问题讨论】:

    标签: php nginx


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 1970-01-01
      • 2018-04-29
      • 2012-07-06
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 2014-09-03
      • 2016-11-05
      相关资源
      最近更新 更多