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

qidizi 2014-05-29 10:57:44
目录结构



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有什么要求?
...全文
171 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qidizi 2014-05-30
  • 打赏
  • 举报
回复
引用 1 楼 zy205817 的回复:
你看看下nginx 可以这样使用 /usr/local/nginx/sbin/nginx -参数 -c <path_to_config>:使用指定的配置文件而不是 conf 目录下的 nginx.conf 。 -t:测试配置文件是否正确,在运行时需要重新加载配置的时候,此命令非常重要,用来检测所修改的配置文件是否有语法错误。
我的意思是在所有的配置中不应该绝对路径. 但是可以在bat的运行时可以出现. 因为我的想法是把所有的web相关文件放到usb中都可以运行. 而bat有编写的能力,那么我应该可以使用bat语法取得到当前bat的绝对路径,然后其它所有配置就应该使用相对路径来指定所有的配置.否则usb的变化就会导致配置不得不写死绝对路径, 这不符合我的要求.
码无边 2014-05-30
  • 打赏
  • 举报
回复
你看看下nginx 可以这样使用 /usr/local/nginx/sbin/nginx -参数 -c <path_to_config>:使用指定的配置文件而不是 conf 目录下的 nginx.conf 。 -t:测试配置文件是否正确,在运行时需要重新加载配置的时候,此命令非常重要,用来检测所修改的配置文件是否有语法错误。

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧