Nginx与php在一个子目录中 [英] Nginx with php in one subdirectory

查看:269
本文介绍了Nginx与php在一个子目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a website in pure HTML. Now I have to add a sub-directory (demo) containing PHP files. I set up two locations in my nginx.conf file:

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/时,它一直在抱怨

Now the mydomain.com works just fine, but when I try to access mydomain.com/demo/, it keeps complaining

No input file specified.

此脚本有什么问题?我猜想某些路径未正确设置,例如fastcgi_index:应该是/demo/index.php吗?我尝试了不同的组合,但没有用.任何帮助将不胜感激!

What's the problem with this script? I guess some path is not correctly setup like fastcgi_index: should it be /demo/index.php? I've tried different combinations but none works. Any help would be appreciated!

推荐答案

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

It's likely that your fastcgi_param should be /www$fastcgi_script_name because the variable is the full URI request. Source.

这篇关于Nginx与php在一个子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆