Nginx:502错误网关

时间:2019-01-10 18:54:03

标签: php nginx websocket server

我的nginx.conf文件看起来像这样:

user www-data;
worker_processes 4;

events {
    worker_connections 1024;
}

http {

    include mime.types;
    server_tokens off;
    root /var/www/html;

    fastcgi_cache_path /tmp/nginx/cache levels=1:2 keys_zone=phpcache:100m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";

    server {
        listen 80;
        server_name localhost;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2;
        server_name localhost;

        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

        add_header Strict-Transport-Security "max-age=31536000" always;

        index index.php index.html;

        location / {
            try_files $uri $uri/ =404;
        }

        location ~\.php {
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_index  index.php;
            include fastcgi_params;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            fastcgi_cache phpcache;
            fastcgi_cache_valid 200 301 302 60m;
            add_header X-FastCGI-Cache $upstream_cache_status;
            fastcgi_cache_bypass $skip_cache;
            fastcgi_no_cache $skip_cache;
        }
    }
}

现在,在打开一些网址时,它会抛出 502错误的网关,但不会抛出其他错误。我在error.log中遇到的错误是:

  

2019/01/10 23:53:39 [错误] 12139#12139:* 5 recv()失败(104:   从对等方重置连接),同时从上游读取响应标头,   客户端:127.0.0.1,服务器:localhost,请求:“ GET / wordpress /   HTTP / 2.0”,上游:“ fastcgi:// unix:/run/php/php7.3-fpm.sock:”,主机:   “本地主机”

请让我知道可能是什么问题。

1 个答案:

答案 0 :(得分:0)

如果PHP无法在文件中记录会话信息,则会发生此问题。检查php.ini文件中的session_save_path。