nginx [engine x] 是由 Igor Sysoev开发的一个HTTP 服务器和mail 代理服务器软件.虽然刚刚发布两年多, Nginx 因其稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。Nginx 超越Apache的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,其中有新浪、网易、腾讯等门户网站,六间房、酷6等视频分享网站,Discuz!、水木社区等知名论坛,豆瓣、YUPOO等新兴Web 2.0网站。Nginx 在国内的应用正在不断发展壮大!新近发现Nginx 应用在国内越发火热了,很多网站都开始转向Nginx 了。
一,首先下载nginx 0.7.52的windows版本,下载地址:http://sysoev.ru/nginx/nginx-0.7.52.zip,并到PHP 官方下载php。
然后,解压nginx-0.7.52.zip到C盘的根目录,并将目录名改为nginx。执行下列操作
1, cd nginx
2, start nginx
这样,nginx就启动了。打开浏览器,输入http://127.0.0.1/ 就可以看到nginx的欢迎页面了。nginx的其他命令
nginx -s stop //停止nginx
nginx -s reload //重新加载配置文件
nginx -s quit //退出nginx
二,那么如何设置,使nginx以fast-cgi模式支持PHP呢?首先,假设你已经以fast-cgi方式安装了PHP。接下来就是配置nginx的conf文件了。下面是我配置好的,可以对照一下.
worker_processes 1;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80; #端口可修改
server_name 127.0.0.1; #可换成自己的域名
charset utf-8; #改字符集,可写为gb2312
location / {
root E:\Works\php; #主目录位址
index index.html index.htm index.php; #主目录默认文件
# autoindex on; #没有默认文件,会列出目录中所有文件
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .*\.php?$ { #开启支持php
root E:\Works\php;
fastcgi_pass 127.0.0.1:9000; #php fastcgl服务地址及端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#或为 fastcgi_param SCRIPT_FILENAME E:\Works\php$fastcgi_script_name; #改为web默认目录
include fastcgi_params;
}
}
三,启动nginx 服务器,再启动php 的FasCGI sever 。关于php FastCGI server 可以使用以下命令:
php-cgi.exe -b 127.0.0.1:9000 -q
这样做,缺陷是命令行窗口一直打开,若关闭那FastCGI server 也关闭啦。到网上下载RunHiddenConsole.exe 可以使命令行窗口隐藏啦。(RunHiddenConsole.exe下载页面 )
RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000 -q
可写一个批处理:
@echo off
start /min RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000 -q
最后,就是写一个简单PHPINFO 来验证PHP ,在目录 E:\Works\php 下新建名为 index.php 的文件,文件内容
<?php
phpinfo();
?>
四,CMD 批处理Start.cmd,可以同时启动Nginx 和PHP FastCGI。
@echo off
REM "正在启动Nginx 服务器........"
cd nginx
start nginx
cd ..
REM "开始启动PHP FastCGI........."
cd php5
start RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000
接下来是一个简单的关闭Nginx 和PHP FastCGI 的脚步Stop.cmd :
@echo off
taskkill /f /im nginx.exe
taskkill /f /im php-cgi.exe