load_module /usr/lib/nginx/modules/ngx_stream_module.so; user www-data; # Debian: www-data / CentOS: nginx worker_processes auto; pid /run/nginx.pid; error_log /var/log/nginx/error.log warn; worker_rlimit_nofile 16384; events { worker_connections 8192; #1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; server_tokens off; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" "$http_user_agent" ' 'proto=$ssl_protocol sni=$ssl_server_name'; access_log /var/log/nginx/access.log main; # WebSocket map,http全局可以保留,只在使用proxy的location引用 map $http_upgrade $connection_upgrade { default upgrade; '' close; } # ---------- HTTPS 服务:SSL 终结,反代内网 5004 ---------- server { listen 127.0.0.1:5005 ssl; http2 on; server_name chanking.zhonjin.com; ssl_certificate /etc/letsencrypt/live/zhonjin.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/zhonjin.com/privkey.pem; ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; location / { proxy_pass http://127.0.0.1:5004; # proxy参数全部收拢在这里,不污染全局http和跳转server proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_connect_timeout 5s; #60s; proxy_read_timeout 3600s; proxy_send_timeout 60s; } } # ---------- HTTP 服务:仅做301跳转,不使用proxy ---------- server { listen 127.0.0.1:5006; server_name chanking.zhonjin.com; return 301 https://$host:40130$request_uri; } #zhonjin_http.conf include 到 nginx.conf 的 http 块中! include /etc/nginx/conf.d/zhonjin_http.conf; } stream { error_log /var/log/nginx/stream_error.log warn; log_format stream_main '$remote_addr [$time_local] $protocol ' 'preread=$ssl_preread_protocol status=$status ' 'upstream=$upstream_addr bytes=$bytes_sent'; map $ssl_preread_protocol $backend_target { "" 127.0.0.1:5006; # 明文HTTP → 301跳转 default 127.0.0.1:5005; # TLS流量 → SSL解密入口 } server { listen 40130 backlog=4096; tcp_nodelay on; ssl_preread on; # nginx >=1.23.4 才启用下面一行,低版本注释掉! 当前版本 1.26.3 #ssl_preread_buffer_size 16k; proxy_pass $backend_target; proxy_connect_timeout 10s; # 3600s 和http proxy_read_timeout对齐 proxy_timeout 3600s; proxy_next_upstream off; access_log /var/log/nginx/stream_access.log stream_main; } # 指向新的独立stream配置目录,不要用conf.d!! # include /etc/nginx/stream-conf/*.conf; include /etc/nginx/stream.d/zhonjin_stream.conf; } # ==========新增这一行include,其他全部不动========== #include /etc/nginx/conf.d/zhonjin.stream.conf;