以前一直在用apache搭建本地站点,但是还是想尝尝nginx。废话不多说:
这是windows下的配置文件的部分选取:
server {
listen 8090;(由于我已经安装了apache,所以端口改为8090)
server_name localhost;
autoindex on;(这是需要我手动添加的,nginx在默认情况下是不显示目录的,加上这个就能在没有索引页面的情况下显示目录)
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root "C:\Program Files\apache2.2\htdocs";(记得英文状态下加引号,否则无法识别目录,将目录指向原先的apache站点目录,不过要想使这个使用正常的话必须要改端口为80哦)
index index.html index.htm index.php;(增加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 "C:\Program Files\apache2.2\htdocs";
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#下面这部分去除注释,然后将绿色的部分由/script改为$document_root
location ~ \.php$ {
root "C:\Program Files\apache2.2\htdocs";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
然后到这里下载:RunHiddenConsole
解压后的到
start.bat的脚本需要修改一下:将php-cgi.exe,php.ini,nginx.exe的路径改为你自己的。
如果找不到php-cgi.exe,你可以上php官网下载windows版的压缩包(注意要下压缩包而非安装包)
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole.exe C:\Program Files (x86)\PHP\php-cgi.exe -b 127.0.0.1:9000 -c C:\Program Files (x86)\PHP\php.ini
echo Starting nginx...
cd I:\Program Files\nginx-1.4.2\
start nginx
一个开启脚本,一个关闭脚本,就不用我说了吧。
ok,重启nginx即可。
测试:站点根目录新建info.php文件(最好用notepad++),内容为
<?php phpinfo (); ?>