搭建windows+Nginx+PHP配置指南 以及 之后的问题解决

来源:互联网 发布:深圳黑马程序员就业 编辑:程序博客网 时间:2024/05/22 10:39
Ps:本文是安装了wamp后的操作。不过没安装也没事,本文也有一定的思路启迪。
本文重点讲Nginx+PHP搭建完毕遇到的问题,搭建其实很简单:
可以参考:http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html

打开nginx的配置文件nginx.conf,找到
location / {
      root   html;      #这里是站点的根目录
      index  index.php index.html index.htm;
}
改成:
location / {
      root   D:/wnmp/www;     
      index  index.html index.htm;
}

# 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;
#}
改成:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
      root           D:/wnmp/www;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
}

改完后,要连接下php-cgi,然后重启下nginx即可。
如何连接php-cgi:
D:\wamp\php>php-cgi.exe -b 127.0.0.1:9000 -c D:/wamp/php/php.ini

Ps:文件的权限要设置好,不然会出现403 Forbidden的。
Ps:如果不搞这个php-cgi会出现页面刷不出来,"An error occured."
Ps:因为很多教程中提到的;cgi.fix_pathinfo,我php.ini没有,都不知道怎么整了,一查资料发现这个;cgi.fix_pathinfo从 PHP 4.3.0 起可用。可是我用的是WAMP,里面的PHP是5.2.5啊!!!算了,不管这个傻逼;cgi.fix_pathinfo。
========================================================================

一.修改完后nginx.conf,出现了403 Forbidden

查看了下log文件中的error.log:
2012/11/05 14:45:19 [error] 4704#4740: *6 directory index of "D:/wamp/php/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:83"
这句话应该就是告诉我这个目录没权限吧。
这个时候发现了我傻逼,我把网站根目录写成了"D:/wamp/php",应该是网站的根目录:"D:/nginx/www"!
改成网站根目录后还是出现了:403  Forbidden,很明显我的权限不足。我想到了可能是要加一些“Everyone“之类的东西吧。但是不知道怎么配置,果断把nginx文件夹放置到wamp(我坚信它一定配置好了各种权限的。)中,并把网站根目录设置为:"D:/wamp/www:",这样子就能够不出现了403  Forbidden了。

二. upstream timed out 未启动fastcgi

然后刷新,发现还是有问题,网页打不开:


查看error.log发现:
2012/11/05 15:17:19 [error] 4992#1528: *10 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /php.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:83"
简单来说就是TIME-OUT,和这个fastcgi有关系

 那么这个fastcgi是干什么吃的呢?
原来是是个cgi(Common GatewayInterface)通用网关接口,它用来连接nginx和PHP的,和php-cgi.exe有关系。
所以很明显,我以上的动作并没有搞过php-cgi.exe,所以导致没人CGI去处理nginx的连接吧,所以一直才会TIMEOUT。。。
用以下语句:
D:\wamp\php>php-cgi.exe -b 127.0.0.1:9000 -c D:/wamp/php/php.ini
启动了php-cgi,然后重新启动nginx,就看到了:








原创粉丝点击