## 1、環境準備

## 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

### 3.2、啟動nginx
* /usr/local/nginx/sbin/nginx

### 3.3、瀏覽器訪問
* 編寫php文件-index.php
```
<?php
echo "hello world.";
```
* curl訪問or瀏覽器訪問

## 4、流程
### 4.1、流程圖

### 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返回給瀏覽器