平台描述:Windows下,使用PHP套件 xampp,因为是测试玩,所以没在服务器 Linux 环境中配置。

1. 首先,将 nginx.conf 中的 PHP 配置注释去掉。

01 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
02 #
03 #location ~ \.php$ {
04 #    root           html;
05 #    fastcgi_pass   127.0.0.1:9000;
06 #    fastcgi_index  index.php;
07 #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
08 #    include        fastcgi_params;
09 #}
10  
11 location ~ \.php$ {
12     root           html;
13     fastcgi_pass   127.0.0.1:9000;
14     fastcgi_index  index.php;
15     fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
16     include        fastcgi_params;
17 }

2. 这里使用的 PHP 是以 cgi 的形式,所以要启用 php-cgi,修改 php.ini,把注释去掉:

1 ;cgi.fix_pathinfo=1
2 cgi.fix_pathinfo=1

3. 启动 php-cgi 和 nginx,下面介绍两个脚本:

start_nginx.bat

01 @echo off
02  
03 REM set PHP_FCGI_CHILDREN=5
04 set PHP_FCGI_MAX_REQUESTS=1000
05   
06 echo Starting PHP FastCGI...
07 RunHiddenConsole D:/xampp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/xampp/php/php.ini
08   
09 echo Starting nginx...
10 RunHiddenConsole D:/nginx/nginx.exe -p D:/nginx/

stop_nginx.bat

1 @echo off
2 echo Stopping nginx... 
3 taskkill /F /IM nginx.exe > nul
4 echo Stopping PHP FastCGI...
5 taskkill /F /IM php-cgi.exe > nul
6 exit

相关下载:RunHiddenConsole.zip

可以看看进程里,如果 nginx 和 php-cgi 都有,那么差不多要成功了。最后,可能会出现 "No input file specified" 的问题,那么修改一下 nginx.conf :

01 location ~ \.php$ {
02     #root           html;
03     root           D:/nginx/html;
04     fastcgi_pass   127.0.0.1:9000;
05     fastcgi_index  index.php;
06     #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
07     #fastcgi_param  SCRIPT_FILENAME D:/nginx/html$fastcgi_script_name;
08     fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
09     include        fastcgi_params;
10 }

注意注释的地方,修改成下面那行,请根据你的具体文件配置路径。

编辑 test.php :

1 <?php
2     phpinfo();
3 ?>

运行 http://localhost:81/test.php,OK。

Windows下配置Nginx使之支持PHP(转)的更多相关文章

  1. windows 下配置 Nginx 常见问题(转)

    windows 下配置 Nginx 常见问题 因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我 ...

  2. Windows下配置Nginx

    一.今天是2017年1月18日.揣着一种也许叫做冲动的心情,决定以后每天都记录和回顾新涉及的技术,巩固已学到的知识,坚持. 二.回归到今天的技术主题,因为之前对于[反向代理]这种技术充满了好奇,借此机 ...

  3. 在CentOS/Windows下配置Nginx(以及踩坑)

    在CentOS/Windows下配置Nginx(以及踩坑) 1. 序言 因为这类文章网上比较多,实际操作起来也大同小异,所以我并不会着重于详细配置方面,而是将我配置时踩的坑写出来. 2. CentOS ...

  4. windows 下配置 Nginx 常见问题

    因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我的系统是win7旗舰版的,到官网下载最新版本 ...

  5. Windows下配置nginx+php(wnmp)

      第一部分:准备工作.(系统:Windows 8.1) 1.首先是下载软件. NGINX-1.3.8官网下载:http://nginx.org/en/download.html PHP5.4.8版本 ...

  6. windows下配置nginx+php环境

    刚看到nginx这个词,我很好奇它的读法(engine x),我的直译是"引擎x",一般引"擎代"表了性能,而"x"大多出现是表示" ...

  7. windows下配置nginx+php

    [转] http://www.cnblogs.com/fengyuqing/p/php_nginx.html 1.首先需要准备的应用程序包. nginx:nginx/Windows-1.0.4 php ...

  8. Windows下配置Apache服务器并支持php

    php环境的配置相对来说比较繁琐,网上教程大部分都是放一起说,总体感觉比较乱,其实Apache是一款通用的服务器软件,可以用来配置支持静态页面,php.Python.Java甚至asp等服务端语言,要 ...

  9. (转)windows下配置nginx+php环境

    原文地址 http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html 刚看到nginx这个词,我很好奇它的读法(engine ...

随机推荐

  1. How far away ?

    #include<iostream> #include <algorithm> using namespace std; const int M=40010; int dis[ ...

  2. zoj3839-Poker Face

    #include<cstdio>int n;void P(int i,int j,int n,int f){ if(i==n){ for(int k=1;k<=n;k++)print ...

  3. Unity3d脚本的生命周期

    接下来,做出一下讲解:最先执行的方法是Awake,这是生命周期的开始,用于进行激活时的初始化代码,一般可以在这个地方将当前脚本禁用:this.enable=false,如果这样做了,则会直接跳转到On ...

  4. WPF之核心面板(容器)控件简单介绍

    一.Canvas 1.官方表述:定义一个区域,在该区域中可以使用相对于该区域的坐标显式定位子元素. 2.对于canvas 的元素的位置,是靠控件的大小及Canvas.Top.Canvas.Left.C ...

  5. qt环境问题导致的编译错误

    /usr/include/qt5/QtCore/qprocess.h:245:24: error: missing binary operator before token "(" ...

  6. Django db relationship

    # coding=utf-8 from django.db import models """ Django数据库关系: 一对一关系:OneToOneField 多对多关 ...

  7. hdu 1229 超级大水题

      Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Desc ...

  8. asp.net 导入

    开发项目过程中会遇到各种各样的项目需求,我现在遇到的问题是每个部门有不同的excel文件类型,他们每个部门每个文件类型上传成功之后都会在数据库中产生表,表的列名是你excel第一行数据,其他行作为表的 ...

  9. hdfs 常用命令

    (2)bin/hdfs dfs -mkdir -p /home/雨渐渐 (3)scp /media/root/DCE28B65E28B432E/download/第2周/ChinaHadoop第二讲\ ...

  10. BZOJ 3893 Cow Jog

    Description The cows are out exercising their hooves again! There are \(N\) cows jogging on an infin ...