## 1、环境准备
![5、nginx与php-fpm结合详解](http://p3.pstatp.com/large/pgc-image/8d9f42e219aa480fab4f2d6e32a0ed18)
## 2、配置
* nginx.conf文件在/usr/local/nginx/conf
```
http {
include mime.types;
default\_type application/octet-stream;
sendfile on;
keepalive\_timeout 65;
server {
listen 81;
server\_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ \\.php$ {
fastcgi\_pass 127.0.0.1:9000;
fastcgi\_index index.php;
fastcgi\_param SCRIPT\_FILENAME /data/php/$fastcgi\_script\_name; #当请求资源是php后缀的文件时,在目录/data/php中查找
include fastcgi\_params;
}
}
}
```
* php-fpm保持默认状态
## 3、运行
### 3.1、启动php-fpm
* /usr/local/php/sbin/php-fpm
![5、nginx与php-fpm结合详解](http://p1.pstatp.com/large/pgc-image/4ec0f1b18be54121867e33be4f3aee25)
### 3.2、启动nginx
* /usr/local/nginx/sbin/nginx
![5、nginx与php-fpm结合详解](http://p9.pstatp.com/large/pgc-image/ba5084fc22d64a25b5e86028f6f39a58)
### 3.3、浏览器访问
* 编写php文件-index.php
```
<?php
echo "hello world.";
```
* curl访问or浏览器访问
![5、nginx与php-fpm结合详解](http://p3.pstatp.com/large/pgc-image/66205baa99234b1084593fcf5278b254)
## 4、流程
### 4.1、流程图
![5、nginx与php-fpm结合详解](http://p9.pstatp.com/large/pgc-image/6e75fe5ce2d14d24998dab0ee5b13a69)
### 4.2、文字描述如下
* 访问http://192.168.0.200:81/index.php
* Nginx查看nginx.conf配置文件
* 加载nginx的fast-cgi模块
* php-fpm 监听127.0.0.1:9000
* php-fpm 接收到请求,启用worker进程处理请求
* php-fpm 处理完请求,返回给nginx
* nginx将结果通过http返回给浏览器