回归正题,测试一下环境,papapa输入127.0.0.1,走你~ 然后Nginx就调皮了:503 Bad Gateway(无效网关)。 叔叔要查监控了哦!老司机开上Terminal,跑到监控室:cd /var/log/nginx,看小视频:sudo vi error.log ,最赤鸡的情节是这样的:
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文件不走网络,是套接字。
php7默认的是socket,按照之前Nginx的conf文件,俩字:没毛病,才怪。(说好了在咖啡厅见,你却偏偏跑到了小树林) 老司机要潜水了:
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
换成fastcgi_pass unix:/run/php/php7.0-fpm.sock;
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 reload**
然后127.0.0.1:8080走你~
viencoding.com版权所有,允许转载,但转载请注明出处和原文链接: https://viencoding.com/article/49