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

qidizi qidizi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
目录结构



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有什么要求?
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
qidizi
PHP 20,393 成员 19,654 内容