我设置了一个 Web 服务器,它通常响应速度极快(<100ms),即使将 keepalive_timeout 设置为 0,重复连接也不会出现连接问题。但是,偶尔在连接到站点时,浏览器会永远停滞,Wireshark 会显示多个未响应的 TCP 重传数据包。NGINX 在访问日志中没有显示任何问题。
/etc/nginx/nginx.conf:
user www-data;
worker_processes 4;
thread_pool default threads=32 max_queue=65536;
pid /run/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 512;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile off;
tcp_nopush off;
tcp_nodelay on;
#keepalive_timeout 10;
keepalive_timeout 0;
#types_hash_max_size 2048;
#client_body_buffer_size 128k;
client_max_body_size 10G;
#client_header_buffer_size 1k;
#large_client_header_buffers 4 4k;
#output_buffers 2 32k;
postpone_output 0;
#server_names_hash_bucket_size 128; # this seems to be required for some vhosts
access_log on;
log_format upstream_time '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"'
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_certificate /etc/letsencrypt/live/www.baldeonline.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.baldeonline.com/privkey.pem;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!DSS';
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_ecdh_curve secp384r1;
resolver 1.1.1.1 8.8.8.8 8.8.4.4;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/www.baldeonline.com/chain.pem;
##
# Logging Settings
##
access_log /var/log/nginx/access.log upstream_time;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_min_length 32;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/www.baldeonline.com:
server {
server_name www.baldeonline.com;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl on;
root "/http/www.baldeonline.com";
include /etc/nginx/generalSubdomainHandler;
location /phpmyadmin/ {
allow 192.168.1.0/24;
allow 10.8.0.0/24;
deny all;
}
location /phppgadmin/ {
allow 192.168.1.0/24;
allow 10.8.0.0/24;
deny all;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name $host;
return 301 https://$host$request_uri;
}