nginx 訪問 php 頁面提示 connect reset by

我在兩臺機器上部署了 nginx 和 php 後,配置了 nginx 支持 php,也啓動了 php-fpm,當我訪問的時候直接報錯了,也不知道什麼緣由php

nginx 搭建

master1 192.168.1.10node

master2 192.168.1.6nginx

[root@master1 ~]# yum -y install nginx
[root@master1 ~]# vim /etc/nginx/nginx.conf
user    nginx;
worker_processes        auto;
pid     /var/run/nginx/nginx.pid;
worker_rlimit_nofile    65535;
events {
    worker_connections  65535;
}
http {
        charset utf-8;
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     on;
        server_tokens   off;
        gzip    on;
        gzip_vary       on;
        gzip_proxied    any;
        gzip_comp_level 6;
        client_max_body_size    32M;
        keepalive_timeout       65;
        #MIME
        include mime.types;
        default_type    application/octet-stream;
        #logging
        log_format      main    '$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for $request_time $upstream_response_time';
        log_format      error   '$remote_addr [$time_local] $request $status $body_bytes_sent $http_referer $http_x_forwarded_for $request_time $upstream_response_time';
        access_log      /data/nginx/log/access.log  main;
        error_log       /data/nginx/log/error.log       error;

        #SSL
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:10m;
        ssl_session_tickets off;
        ssl_protocols TLSv1.3;
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 8.8.8.8 8.8.4.4 208.67.220.220 valid=60s;
        resolver_timeout 2s;
        upstream phpstream {
# ip_hash;
# keepalive 20; #若是要開啓它,須要設置fastcgi_keep_conn 爲 on
                server  172.17.20.170:9000      max_fails=5     fail_timeout=3;
                server  172.17.20.171:9000      max_fails=5     fail_timeout=3;
                server  172.17.20.172:9000      max_fails=5     fail_timeout=3;
                server  172.17.20.173:9000      max_fails=5     fail_timeout=3;
        }
        server {
                listen       80 default_server;
          # server_name localhost;
                location ~ \.php$ {
                    root    /usr/local/var/www/;  #master2 主機上 php 腳本存在的位置
                    fastcgi_pass phpstream;
                    fastcgi_index  index.php;
                    fastcgi_keep_conn on;
                    fastcgi_param  SCRIPT_FILENAME  /usr/local/var/www/$fastcgi_script_name;
                    include    fastcgi_params;
                }
        }
    }
複製代碼

安裝 php

[root@master2 ~]# yum install php php-fpm
[root@master2 ~]# vim /etc/php-fpm.d/www.conf
........
listen = 0.0.0.0:9011
user=nginx
group=nginx
listen.allowed_clients=any
........
[root@master2 ~]# cat /usr/local/var/www/index.php
<?php
phpinfo();
?>
複製代碼
當訪問的時候nginx 日誌報錯以下。當訪問不頻繁的時候報的是第二條,頻繁的時候報的是第一條,沒法返回正常頁
[root@master1 ~]# cat /var/log/nginx/error.log
2019/10/29 22:25:02 [error] 16763#0: *146 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.6, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://192.168.1.6:9011", host: "192.168.1.10"
2019/10/29 22:25:07 [error] 16763#0: *146 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.6, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://192.168.1.6:9011", host: "192.168.1.10"
複製代碼

誰知道這兩個問題怎麼解決?麻煩提供一下解決思路。

PS:已經解決完了,問題是由於listen.allowed_clients=any參數的問題,按照官方的解釋是:容許那些fastcgi客戶端來進行鏈接,若是留空的話會容許全部的主機,默認值爲any,設置爲any不生效,註釋掉這個配置就能夠正常訪問了

相關文章
相關標籤/搜索