Nginx与php在一个子目录中 [英] Nginx with php in one subdirectory
问题描述
我有一个纯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屋!