ubuntu php7 nginx

Ubuntu16.10下php7.0-fpm与Nginx配置 来源: qq_32457355的博客  

Problem!!!

回归正题,测试一下环境,papapa输入127.0.0.1,走你~
然后Nginx就调皮了:503 Bad Gateway(无效网关)。
叔叔要查监控了哦!老司机开上Terminal,跑到监控室:cd /var/log/nginx,看小视频:sudo vi error.log ,最赤鸡的情节是这样的:

?
1
2016 / 12 / 25 22 : 45 : 18 [error] 13153 # 13153 : * 1 connect() failed ( 111 : Connection refused) while connecting to upstream, client: :: 1 , server: localhost, request: "GET / HTTP/1.1" , upstream: "fastcgi://127.0.0.1:9000" , host: "localhost:8080"

Nginx处理请求是通过fpm 管理fastcgi来实现请求和相应,而Nginx和php-fpm可以通过监听9000端口(default)或者socket来实现。127.0.0.1:9000走网络,通过Nginx的conf文件,把php结尾的都交给9000端口处理,php-fpm(fastcgi的进程管理器)选择并且连接到一个fastcgi子进程,并将环境变量和标准输入发送到fastcgi子进程,然后不断处理请求响应。socket文件不走网络,是套接字

Conflict!!!

好多强迫症的朋友手一抖,papapa从Ubuntu15,升级到16,然后刚刚还跑的好好地程序,突然抛锚了,然后一番折腾,死活找不到锚抛到哪里了。

php7默认的是socket,按照之前Nginx的conf文件,俩字:没毛病,才怪。(说好了在咖啡厅见,你却偏偏跑到了小树林)
老司机要潜水了:

?
1
2
3
4
5
6
7
8
9
10
11
cd /etc/php/ 7.0 /fpm 
sudo vim php-fpm.conf
发现最后:
include=/etc/php/ 7.0 /fpm/pool.d/*.conf
按照上面的线索继续找
cd /etc/php/ 7.0 /fpm/pool.d
ll之后发现只有一个www.conf
sudo vim www.conf
找了一下发现
listen = /run/php/php7. 0 -fpm.sock
; listen = 127.0 . 0.1 : 9000

Resolve!!!

该去Nginx的配置文件搞事情了

sudo vim /etc/nginx/sites-available/default  注释fastcgi_pass 127.0.0.1:9000;  换成fastcgi_pass unix:/run/php/php7.0-fpm.sock;
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
     listen 8080 ;
     listen [::]: 8080 ;
     server_name localhost;
 
     root /home/moma/vien/learn/php/demo01/;
     index index.html index.htm index.php;
 
     location / {
         try_files $uri $uri/ /index.php$is_args$args;
     }
 
     location ~ \.php$ {
         try_files $uri = 404 ;
 
         include fastcgi.conf;
         # fastcgi_pass 127.0 . 0.1 : 9000 ;
         # 换成socket
         fastcgi_pass unix:/run/php/php7. 0 -fpm.sock;
         #change by me
         fastcgi_index index.php;
         fastcgi_intercept_errors     on;
         #fastcgi_param SCRIPT_FILENAME /home/gittest/$fastcgi_script_name;
         include     fastcgi_params;
     }
}

OK

重新加载Nginx和php-fpm

sudo service nginx reload  sudo service php7.0-fpm

然后127.0.0.1:8080走你~

猜你喜欢

转载自www.cnblogs.com/shenwenkai/p/9295929.html