各位请教一个nginx与php-cgi的配置问题(版块不明,请管理移动)
目录结构

nginx启动方式
nginx配置目录结构,这里在nginx.conf中使用include vhost/*.conf

在nginx/conf/vhost/有文件 www.cnntaa.com.conf
配置如下
使用上面这个配置运行
web/www/ntaa/phpcms/www/index.html
显示效果如图(反正是root是正确的内容出来了)

再运行
web/www/ntaa/phpcms/www/t.php
代码如下
<?php
echo "<pre>";
var_export($_SERVER);
echo "</pre>";
效果如下(php解析)了

下面把www.cnntaaa.com.conf中的php的root修改成相对的.就会出现问题
注意这里没有放出其它配置代码,跟上面是一样的,唯一不同处就是把root注释掉(红色字)
这时, $document_root按我的理解它应该是 ./../www/cnntaa/phpcms/www
就是
SCRIPT_FILENAME === ./.../www/cnntaaa/phpcms/www/t.php
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
#这里只能使用绝对路径
#root d:/web/www/ntaa/phpcms/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
这时重新启动nginx,查看
http://www.cnntaa.com/index.html时,效果与上面的图片没有变化,也就是说,nginx这时root是支持相对路径 的.
但是,对于php-cgi.exe却不行了.效果如下图
当然,这就是明显的找不到t.php了.

我想问一下.
如果我要配置相对路径(绝对路径就不用说了,上面的配置没有问题的.)
要怎么弄?
我有什么办法看到 nginx这时把 SCRIPT_FILENAME发给php-cgi时是什么?这个我可能大概想到.
这时的php-cgi对于 SCRIPT_FILENAME解析是怎么样的?它的相对路径是那里?对 SCRIPT_FILENAME有什么要求?

nginx启动方式
set bat=%~f0
set batDir=%~dp0
CD "%batDir%"
set log=%batDir%log\
::启动nginx服务
:callLabel8
set called=1
start "fcgi服务" /MIN /D "%batDir%php" php-cgi.exe -b 127.0.0.1:9000 -c "%batDir%php/php.ini"
start "nginx服务" /MIN /D "%batDir%nginx" nginx.exe
:eof_callLabel8
goto :EOF
::eof_启动nginx服务
::停止nginx服务
:callLabel9
set called=1
start "停止php-cgi服务" /MIN /D "%batDir%php" taskkill /F /IM php-cgi.exe > nul
start "nginx服务" /MIN /D "%batDir%nginx" nginx.exe -s stop
:eof_callLabel9
goto :EOF
::eof_停止nginx服务nginx配置目录结构,这里在nginx.conf中使用include vhost/*.conf

在nginx/conf/vhost/有文件 www.cnntaa.com.conf
配置如下
server {
listen 80;
server_name www.cnntaa.com
cnntaa.com;
access_log ./../log/cnntaa.com.access.txt;
#charset koi8-r;
location / {
index index.html index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
root ../www/ntaa/phpcms/www;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
#这里只能使用绝对路径
root d:/web/www/ntaa/phpcms/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
使用上面这个配置运行
web/www/ntaa/phpcms/www/index.html
<!DOCTYPE html>
<html>
<head>
<!--#include virtual="/fragment/header.htm"-->
<!--#include virtual="/fragment/seajs.htm"-->
</head>
<body>
<!--#include virtual="/fragment/nav.htm"-->
fffdddd
<!--#include virtual="/fragment/footer.htm"-->
</body>
</html>
显示效果如图(反正是root是正确的内容出来了)

再运行
web/www/ntaa/phpcms/www/t.php
代码如下
<?php
echo "<pre>";
var_export($_SERVER);
echo "</pre>";
效果如下(php解析)了

下面把www.cnntaaa.com.conf中的php的root修改成相对的.就会出现问题
注意这里没有放出其它配置代码,跟上面是一样的,唯一不同处就是把root注释掉(红色字)
这时, $document_root按我的理解它应该是 ./../www/cnntaa/phpcms/www
就是
SCRIPT_FILENAME === ./.../www/cnntaaa/phpcms/www/t.php
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
#这里只能使用绝对路径
#root d:/web/www/ntaa/phpcms/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
这时重新启动nginx,查看
http://www.cnntaa.com/index.html时,效果与上面的图片没有变化,也就是说,nginx这时root是支持相对路径 的.
但是,对于php-cgi.exe却不行了.效果如下图
当然,这就是明显的找不到t.php了.

我想问一下.
如果我要配置相对路径(绝对路径就不用说了,上面的配置没有问题的.)
要怎么弄?
我有什么办法看到 nginx这时把 SCRIPT_FILENAME发给php-cgi时是什么?这个我可能大概想到.
这时的php-cgi对于 SCRIPT_FILENAME解析是怎么样的?它的相对路径是那里?对 SCRIPT_FILENAME有什么要求?
...全文
相关推荐
Windows下Nginx和php-cgi的bat批处理快速启动方法
Windows下Nginx和php-cgi的bat批处理快速启动方法!!!!
RunHiddenConsole xxfpm nginx windows php-cgi进程维护工具
解决windows下的Nginx和php搭配 php-cgi.exe自动关闭退出问题。用压缩包内bat文件启动即可,路径要稍微修改一下。
让 Nginx 支持 cgi
NULL 博文链接:https://zachary-guo.iteye.com/blog/1554807
nginx+php-cgi 进程守护工具
本工具为易语言编写,可能有误报,请自行辨识。 nginx+php 在 Windows 环境下的进程守护工具, 防止连接数达到上限后 php-cgi 进程退出而导致服务终止。 修改配置 Web.ini: nginx_dir => 填写 nginx.exe 所在目录 php_cgi_dir => 填写 php-cgi.exe 所在目录 php_cgi_start => 填写 php-cgi 启动参数及端口 php_cgi_num => 填写同时运行 php-cgi 的个数 其他使用默认配置即可 工具简陋,原本供自己使用,现方便有相同需求的人。 压缩包内有邮箱,有疑问可发邮件。
Ubuntu中Nginx服务器安装配置教程
Ubuntu中Nginx服务器安装配置教程


