Nginx无法增加proxy_read_timeout

时间:2019-06-02 01:03:31

标签: nginx websocket proxy ratchet

我正在使用Nginx(1.16.0)+ PHP-FPM(7.3.5)。我需要增加websocket超时时间。 Nginx文档说默认超时是60s,但是连接将在100-110s内关闭(我不知道为什么)。

我尝试用proxy_read_timeout 600;增加它,但是没有效果。另外,如果我输入proxy_read_timeout 30;,则无法正常工作。仅当我使用proxy_connect_timeout时有效:

proxy_connect_timeout 10;
proxy_read_timeout 30;

这样,连接会在30秒后关闭,但是如果我对它进行高评估,它将无法正常工作。

我将日志置于调试模式,但是没有错误。我试图将proxy_read_timeout放在http{}块中,但是没有任何变化。我正在使用Ratchet Websocket,并且在Apache中没有这个问题。

这是我的nginx.conf

load_module modules/ngx_http_modsecurity_module.so;

user nobody;
worker_processes 1;
error_log               /var/log/nginx/error.log error;
pid                     /var/run/nginx.pid;

events {
    worker_connections  5000;
    use                 epoll;
    multi_accept        on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    modsecurity on;
    modsecurity_rules_file /etc/nginx/modsec/main.conf;

    client_header_timeout 12s;
    client_body_timeout 12s;
    client_max_body_size 2m;
    client_header_buffer_size 4k;
    client_body_buffer_size 128k;
    large_client_header_buffers 2 2k;

    send_timeout 3s;
    keepalive_timeout 15 15;
    reset_timedout_connection       on;
    server_names_hash_max_size 1024;
    server_names_hash_bucket_size 1024;
    ignore_invalid_headers on;
    connection_pool_size 256;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;

    include mime.types;
    default_type application/octet-stream;

    # SSL Settings
    ssl_certificate         /etc/nginx/ssl/cf_cert.pem;
    ssl_certificate_key     /etc/nginx/ssl/cf_key.pem;
    ssl_client_certificate /etc/nginx/ssl/origin-pull-ca.pem;
    ssl_verify_client on;
    ssl_protocols       TLSv1.1 TLSv1.2;

    # Logs
    log_format  main    '$remote_addr - $remote_user [$time_local] $request '
                        '"$status" $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    log_format  bytes   '$body_bytes_sent';
    access_log off;

    # Cache bypass
    map $http_cookie $no_cache {
        default 0;
        ~SESS 1;
        ~wordpress_logged_in 1;
    }

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    server {
        listen 443 ssl http2; 
        server_name domain.com;
        root /home/username/public;
        index index.php index.html;

        access_log /var/log/domain/domain.com.bytes bytes;
        access_log /var/log/domain/domain.com.log combined;
        error_log /var/log/domain/domain.com.error.log debug;

        location / {
            location ~.*\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {      
                expires max;
            } 

            location ~ [^/]\.php(/|$) {
                try_files $uri =404;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass    unix:/opt/alt/php-fpm73/usr/var/sockets/username.sock;
                fastcgi_index   index.php;
                include         /etc/nginx/fastcgi_params;
            }
        }

        location ~ ^/websocket/.* {
            proxy_pass http://127.0.0.1:2053;

            proxy_connect_timeout   10;
            proxy_read_timeout      3600;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
}

0 个答案:

没有答案