Nginx 下载文件突然变慢

Nginx 下载文件突然变慢

从一周前开始,Nginx 在下载小文件和提供内容时变得非常慢。例如,在同一台服务器上下载 500kb 文件需要 10 毫秒到 6 秒。感觉好像它受到了某种限制。奇怪的是,在过去的几个月里我没有更改任何 Nginx 配置文件。

所以我检查了一下我的服务器是否出了问题。我通过 sftp 上传和下载了一个文件,在 1gb 连接上达到了 900mb/s。我还检查了 CPU 和磁盘使用情况,但一切似乎都正常。

我用 Postman 做了一些测试,发现实际 HTTP 响应本身的时间是几毫秒,但之后下载文件需要很长时间。

当我使用 HTTP 而不是 HTTPS 时,这种情况也很奇怪。HTTPS 在本地网络上完全可以正常工作,但如果我从网络外部通过 HTTPS 下载相同的文件,速度又会变慢。HTTP 总是很慢。

我不知道现在该做什么,或者我还能检查什么。我还创建了一个具有相同配置的新 Ubuntu VM,并且在那里遇到了同样的问题,所以我猜是配置出了问题,但我不知道是什么。

这是我的 nginx.conf 文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;


events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

     gzip_vary on;
     gzip_proxied any;
     gzip_comp_level 6;
     gzip_buffers 16 8k;
     gzip_http_version 1.1;
         gzip_min_length 256;
     #gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
         gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

        ### Include a blocklist file
        include /etc/nginx/nginx-acces.conf;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

这是我的站点启用的配置之一:

server {
    server_name resources.example.io www.resources.example.io;
    location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.1.105:8083;
        allow all;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/resources.example.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/resources.example.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = resources.example.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name resources.example.io www.resources.example.io;
    listen 80;
    return 404; # managed by Certbot


}

相关内容