今天心血来潮玩一下在windows nginx+apache,既nginx前端处理静态文件,apache处理动态php程序,为什么要这么做请看nginx和apache哪个好
这里apache用得就是XAMPP集成环境,这只是一个小实验,集成环境就够了,之前讲过集成环境的感想请看Windows下PHP开发环境
好了apache已经有了,nginx从http://nginx.org/en/download.html官网上下载
我选的是nginx/Windows-1.7.9这个版本,下载下来的压缩包你会看一个nginx.exe,双击一下就启动了,很简单吧,运行一下你会看到
好了废话不对说了,直接讲怎么配置吧,其实也很简单
nginx配置文件在conf文件夹下的nginx.conf就是,打开文件
listen 80; 修改成 listen 8081;
我这里apache的端口是80,所以要修改端口,你也可以把apache的80端口改掉,这样nginx的端口就不用修改了
location ~ \.php$ { proxy_pass http://127.0.0.1; }
上面代码中得注释去掉,意思是php文件,到apache去处理,
这里还有一点,要把nginx的目录修改成跟你的apache主目录一样,
默认的目录是
location / { root html; index index.html index.htm; } 修改成 location / { root D:/www/basic/web; index index.html index.htm; }
在测试一下是不是成功了,很简单吧