欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

nginx php 配置 windows_Windows下配置Nginx使之支持PHP

发布时间:2025/3/21 php 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 nginx php 配置 windows_Windows下配置Nginx使之支持PHP 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

平台描述:Windows下,使用PHP套件 xampp,因为是测试玩,所以没在服务器 Linux 环境中配置。

1. 首先,将 nginx.conf 中的 PHP 配置注释去掉。

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi_params;

}

2. 这里使用的 PHP 是以 cgi 的形式,所以要启用 php-cgi,修改 php.ini,把注释去掉:

;cgi.fix_pathinfo=1

cgi.fix_pathinfo=1

3. 启动 php-cgi 和 nginx,下面介绍两个脚本:

start_nginx.bat

@echo off

REM set PHP_FCGI_CHILDREN=5

set PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI...

RunHiddenConsole D:/xampp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/xampp/php/php.ini

echo Starting nginx...

RunHiddenConsole D:/nginx/nginx.exe -p D:/nginx/

stop_nginx.bat

@echo off

echo Stopping nginx...

taskkill /F /IM nginx.exe > nul

echo Stopping PHP FastCGI...

taskkill /F /IM php-cgi.exe > nul

exit

可以看看进程里,如果 nginx 和 php-cgi 都有,那么差不多要成功了。最后,可能会出现 "No input file specified" 的问题,那么修改一下 nginx.conf :

location ~ \.php$ {

#root html;

root D:/nginx/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

#fastcgi_param SCRIPT_FILENAME D:/nginx/html$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

注意注释的地方,修改成下面那行,请根据你的具体文件配置路径。

编辑 test.php :

phpinfo();

?>

运行 http://localhost:81/test.php,OK。

总结

以上是生活随笔为你收集整理的nginx php 配置 windows_Windows下配置Nginx使之支持PHP的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。