Nginx 提供静态数据的速度非常慢
我在 nginx 反向代理后面托管一个 RoR 应用程序,并将 nginx 配置为直接提供所有静态数据,而不将其传递到 RoR 应用程序(由瘦服务器托管)。
现在有趣的是,图像、样式表、JavaScript 等的下载速度非常非常慢<; 10kB/秒。但如果我尝试直接从瘦服务器下载相同的文件,它会全速传送> 1MB/秒。
示例:
www.example.com/files/big_file.zip ->非常慢
www.example.com:3000/files/big_file.zip ->非常faaaast
有人知道这个瓶颈可能发生在哪里吗?或者有人可以为我提供一些 nginx 配置想法吗?
有关环境的更多信息: 英特尔酷睿 i7-920 四核 8GB 内存
Debian Squeeze 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;
}
最好的问候, 埃尔·克诺基
I host a RoR application behind a nginx reverse proxy and configured nginx to serve directly all static data, without passing it to the RoR app (hosted by Thin server).
The funny thing now is that images, stylesheets, javascripts, etc. are downloaded really, really slow < 10kB/s. But if i try to download the same file from the Thin server directly it is delivered at full speed > 1MB/s.
Example:
www.example.com/files/big_file.zip -> very sloooow
www.example.com:3000/files/big_file.zip -> very faaaast
Does someone have an idea, where this bottleneck might happen? Or could someone provide me with some nginx configuration ideas?
Some more information about the environment:
Intel Core i7-920 Quad-Core
8GB Ram
Debian Squeeze
Nginx 1.0.6
This is the 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;
}
Best Regards,
El Knokki
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 ruby 机架应用程序 (sinatra)、unicorn 和 nginx 上遇到了完全相同的问题。我觉得自己像个白痴,因为我为此租用了一台与您的规格完全相同的德国专用服务器。我的解决方法是暂时将所有内容放入 S3/Cloudfront,因为我找不到问题的根源。并不有趣,但希望同时在负载下有所帮助。
I am having the exact same issue with a ruby rack application (sinatra), unicorn and nginx. I feel like an idiot because I have rented a German dedicated server with exactly the same specs like yours for that purpose. My workaround consists of having all that stuff put up to S3/Cloudfront for the moment as I couldn't find the root of the problem. Not amusing but hopefully will help under load meanwhile.