环境:
Windows 7 32位
nginx 1.1.7 dev
php 5.3.8
mysql 5.5.17
RunHiddenConsole和MySQL绿色版下载http://dl.dbank.com/c0ejffpgkx
开始前的准备:
1.目录:
wnmp/
nginx/
start.bat
conf/vhosts.conf
php/
mysql/
wwwroot/
vhosts/
RunHiddenConsole.exe
start.bat
stop.bat
解压nginx、php分别到nginx、php目录
2.修改php.ini
一定要记得修改extension_dir,改成ext即可。之前好几次粗心忘了改,结果所有扩展死活不起作用。
然后修改如下值:
cgi.force_redirect=1
cgi.fix_pathinfo=1
fastcgi.impersonate=1
cgi.rfc2616_headers=1
分别什么意思,在php.ini里面相应位置都有说明。
然后开启需要开启的扩展,有些扩展是有依赖的,就是开启某些扩展之前必须要先开启其依赖的扩展才能正常使用。
3.修改nginx/conf/nginx.conf
- worker_processes 1;
- error_log logs/error.log;
- events {
- worker_connections 64;#这里就不用默认的1024了,我们本地调试用不了这么多
- }
然后是http里关于fastcgi的配置,记得配置在http内server外。
- http {
- #......
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 128k;
- server {
- #...
- }
- }
在然后是默认网站的设置
- server {
- listen 80;
- servername localhost 127.0.0.1;
- index index.htm index.html index.php;
- root html;#这里是相对目录,如果要换到整个环境根目录下的wwwroot必须使用绝对路径,../../wwwroot是不行的,方法还在摸索中。其他虚拟主机同样
- location ~ .*\.(php)?$ {
- fastcgi_pass 127.0.0.1:9000
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_split_path_info ^(.+\.php)(.*)$;
- include conf/fastcgi_params;
- }
- }
然后在配置其他“虚拟主机配置”
- http {
- server {
- #.....
- }
- include conf/vhosts.conf
- }
vhosts.conf
- server {
- listen 80;
- servername a.com *.ab.com;
- index index.htm index.html index.php;
- root X:\wnmp\vhosts\xxx;#这里是相对目录,如果要换到整个环境根目录下的wwwroot必须使用绝对路径,../../wwwroot是不行的,方法还在摸索中。其他虚拟主机同样
- location ~ .*\.(php)?$ {
- fastcgi_pass 127.0.0.1:9000
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_split_path_info ^(.+\.php)(.*)$;
- include conf/fastcgi_params;
- }
- }
多个虚拟主机直接在vhosts.conf里加配置就行。
4.编写配置脚本
nginx/start.bat
- cd nginx
- %cd%/../RunHiddenConsole nginx
- cd ..
根目录下的start.bat
- @echo off
- set PHP_FCGI_MAX_REQUESTS=1000
- echo 正在启动PHP FastCGI...
- RunHiddenConsole php\php-cgi.exe -c 127.0.0.1:9000 -c php\php.ini
- echo 正在启动Nginx...
- call nginx\start.bat
- echo 正在启动MySQL...
- RunHiddenConsole mysql\bin\mysqld-nt.exe
- echo 启动成功...
根目录下的stop.bat
- @echo off
- echo 正在停止PHP FastCGI...
- taskkill /F /IM php-cgi.exe > nul
- echo 正在停止Nginx...
- taskkill /F /IM nginx.exe > nul
- echo 正在停止MySQL
- taskkill /F /IM mysqld-nt.exe
到此,配置结束。
修补一下nginx的漏洞(实际上是php的)
修改nginx/conf/fastcgi_params.conf最开头加上
- if ($request_filename ~* (.*)\.php) {
- set $php_url $1;
- }
- if (!-e $php_url.php) {
- return 403;
- }