【问题标题】:Nginx serves static data very slowlyNginx服务器静态数据很慢
【发布时间】:2011-09-06 19:24:10
【问题描述】:

我在 nginx 反向代理后面托管了一个 RoR 应用程序,并将 nginx 配置为直接提供所有静态数据,而不将其传递给 RoR 应用程序(由瘦服务器托管)。

现在有趣的是图像、样式表、javascript 等的下载速度非常非常慢 1MB/s 的全速传输。

示例:

www.example.com/files/big_file.zip -> 很慢

www.example.com:3000/files/big_file.zip -> 非常棒

有人知道这个瓶颈可能发生在哪里吗?或者谁能​​给我一些nginx配置思路?

更多关于环境的信息: 英特尔酷睿 i7-920 四核 8GB 内存

Debian 挤压 Nginx 1.0.6

这是 nginx.conf

user  www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;


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

    # increase upload file sieze
    client_max_body_size 200M;
}

最好的问候, 埃尔克诺基

【问题讨论】:

    标签: ruby-on-rails performance static nginx thin


    【解决方案1】:

    我在使用 ruby​​ rack 应用程序 (sinatra)、unicorn 和 nginx 时遇到了完全相同的问题。我觉得自己像个白痴,因为我为此租用了与您的规格完全相同的德国专用服务器。我的解决方法包括暂时将所有这些东西放到 S3/Cloudfront 上,因为我找不到问题的根源。不好玩,但希望同时能在负载下有所帮助。

    【讨论】:

    • 问题在一夜之间自行解决。这听起来可能很奇怪,但我什么也没做。甚至没有重新启动nginx。我回家了,第二天 nginx 以闪电般的速度传送所有文件。谢谢你的帖子!
    • 嗯,是的,在使用sendfile 设置下载部分后,我使用nginx 的速度也非常低。但是当我在几个小时后检查时,它工作得很好。事实上,速度使我的连接达到极限。
    猜你喜欢
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多