我的一台服务器出现问题,无法解决。在 Chrome 中,我在处理图片或 css/js 脚本时不断收到 net::ERR_CONTENT_LENGTH_MISMATCH 错误。Nginx 不是代理,它自己提供文件服务。这个错误不会每次都出现,在我刷新页面后它就会消失。它会出现 在与服务器具有快速互联网连接的计算机上(测试了多个网络)。它也会出现 在 Firefox 中,但错误消息不同。我试过在服务器上禁用 gzip,禁用文件元数据缓存,但都没用。过了一段时间,我发现这个错误只出现在 https 上,而不是 http 上。所以我试着更改 SSL 密码,将 SSL 证书从 Letsencrypt 更改为 Comodore,但都没用。我更新了 nginx,问题仍然存在。
user nginx;
worker_processes 12;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
events {
worker_connections 20000;
#use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
#open_file_cache max=200000 inactive=20s;
#open_file_cache_valid 30s;
#open_file_cache_min_uses 2;
#open_file_cache_errors off;
open_file_cache off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
error_log /var/log/nginx/error.log error;
access_log /var/log/nginx/access.log main;
#access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 60;
keepalive_requests 1000;
send_timeout 40;
reset_timedout_connection on;
proxy_buffering on;
fastcgi_buffers 512 16k;
fastcgi_buffer_size 128k;
fastcgi_busy_buffers_size 512k;
fastcgi_connect_timeout 20s;
fastcgi_send_timeout 120s;
fastcgi_read_timeout 120s;
fastcgi_temp_file_write_size 512k;
server_names_hash_bucket_size 100;
client_body_buffer_size 2m;
client_max_body_size 2000m;
client_header_buffer_size 32k;
#large_client_header_buffers 8 8k;
gzip off;
gzip_comp_level 4;
gzip_vary on;
gzip_min_length 2000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/javascript application/xml;
#gzip_disable "MSIE [5-6]\.";
include /etc/nginx/conf.d/*.conf;
}
现在我已经禁用 gzip。
我的相关vhost文件是:
listen *:80;
listen *:443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:EECDH:EDH:!MD5:!RC4:!LOW:!MEDIUM:!CAMELLIA:!ECDSA:!DES:!DSS:!3DES:!NULL;
ssl_certificate /path/to/cert.crt;
ssl_certificate_key /path/to/key.key;
该服务器是配备 HT、64 GB RAM 和 SSD 的 6 核 Xeon。SSD 已占用 50%。网络负载不是很高。任何帮助都将不胜感激。
答案1
我今天遇到了同样的问题,当我检查服务器 nginx 日志时,发现了以下错误信息:
2023/08/03 19:01:20 [crit] 97014#0: *4725 open() "/opt/homebrew/var/run/nginx/proxy_temp/5/01/0000000015" failed (13: Permission denied) while reading upstream, client: 192.168.10.62, server: dev-tex.poemhub.top, request: "GET /node_modules/.vite/deps/chunk-QPHASEO2.js?v=a37c8ef9 HTTP/1.1", upstream: "http://127.0.0.1:3003/node_modules/.vite/deps/chunk-QPHASEO2.js?v=a37c8ef9", host: "dev-tex.poemhub.top", referrer: "http://dev-tex.poemhub.top/node_modules/.vite/deps/react-dom_client.js?v=a37c8ef9"
然后我检查 nginx 组和用户,使用此命令使 proxy_temp 文件夹保持不变:
sudo chown -R <user> /opt/homebrew/var/run/nginx/proxy_temp
sudo chgrp -R <group> /opt/homebrew/var/run/nginx/proxy_temp
作品。
答案2
将 SSL 缓冲区大小减少到 4k:
ssl_buffer_size 4k;
文档:https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size