注:
1. 仅在Windows 7环境使用过,日期为2015-8-11,其他环境仅供参考。
2. 仅提供最简单的配置
快捷安装与配置
nginx.conf
的server块:<code>server { # 替换为需要的端口 listen 80<span>;</span> server_name localhost<span>;</span> # 替换为需要的目录 root D:/Projects/nginx-html<span>;</span> index index.html index.htm index.php<span>;</span> location ~ \.php$ { include fastcgi.conf<span>;</span> # 连接到本机 PHP FastCGI Server 开启的端口 fastcgi_pass 127.0.0.1:9001<span>;</span> } }</code>
nginx
与php-cgi
所在的目录添加到Path环境变量 nginx
server块的location块fastcgi_pass
配置一致<code>php<span>-cgi</span><span>-b</span><span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span></code>
<code><span><?php </span><span>echo</span><span>"<h1>PHP works!</h1>"</span>;</span></code>
server块的server_name与listen
配置好的地址与端口(例如http://localhost:80/index.php
),并看到“PHP works!”说明成功了! Windows下快捷启动、重启、关闭Nginx服务
nginx-start.bat
,并写入<code>@echo off echo Starting php-cgi <span>...</span> RunHiddenConsole php-cgi -b <span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span> echo Starting nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> RunHiddenConsole nginx pause</code>
nginx-reload.bat
并写入<code>@echo off echo Reloading Nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> nginx -s reload pause</code>
nginx-quit.bat
并写入<code>@echo off echo Closing php-cgi <span>...</span> taskkill /IM php-cgi.exe echo Closing nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> nginx -s quit pause</code>
nginx-start
、nginx-reload
、nginx-quit
即可快捷启动、重启、关闭Nginx服务及php-cgi参考:
1. 如何正确配置Nginx+PHP
2. Windows下Nginx+PHP5的安装与配置方法
版权声明:本文为博主原创文章,转载请注明出处。虽然我觉得没什么好转的东西。。。
以上就介绍了最简单的Nginx+PHP,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。