Nginx服务静态文件的方式太慢了

前端之家收集整理的这篇文章主要介绍了Nginx服务静态文件的方式太慢了前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在Stack Overflow上问过这个问题,但对于SF工作人员来说,这可能更像一个问题.

因此最近有很多文章this one,与轻型前端Web服务器结合使用时,颂扬Django静态生成器的优点.这对我来说很有意义.

但是,我没有得到其他人报告的结果 – 每秒数千个请求 – 我不知道为什么会这样.

我正准备对我的报纸网站进行重新设计.我现在在测试服务器上使用静态生成器.当我在特定的静态页面上运行Apache Bench时,我得到了相当悲惨的结果:

ab -c 10 -n 1000 http://journal.streamlister.com/news/

  1. Concurrency Level: 10
  2. Time taken for tests: 53.011 seconds
  3. Complete requests: 1000
  4. Failed requests: 0
  5. Write errors: 0
  6. Total transferred: 21281212 bytes
  7. HTML transferred: 21067360 bytes
  8. Requests per second: 18.86 [#/sec] (mean)
  9. Time per request: 530.107 [ms] (mean)
  10. Time per request: 53.011 [ms] (mean,across all concurrent requests)
  11. Transfer rate: 392.04 [Kbytes/sec] received

当围攻开启的时候我在服务器上看顶部,我可以看到它根本没有击中Apache或数据库服务器.事实上,它正在为缓存页面提供服务. Nginx正在运行,但它永远不会超过2%的内存使用量. cpu保持闲置约95%.

我究竟做错了什么?我能以某种方式错误配置Nginx吗?我的主配置文件粘贴在下面;这个网站特有的包含几乎是Static Generator home page上的示例配置的副本.我在Slicehost 256k切片上运行Ubuntu 9.10.

  1. user not_my_real_username;
  2. worker_processes 4;
  3. error_log /var/log/Nginx/error.log;
  4. pid /var/run/Nginx.pid;
  5. events {
  6. worker_connections 8192;
  7. }
  8. http {
  9. include /etc/Nginx/mime.types;
  10. default_type application/octet-stream;
  11. access_log /var/log/Nginx/access.log;
  12. sendfile on;
  13. #tcp_nopush on;
  14. keepalive_timeout 0;
  15. #keepalive_timeout 65;
  16. tcp_nodelay on;
  17. gzip on;
  18. include /etc/Nginx/conf.d/*.conf;
  19. include /etc/Nginx/sites-enabled/*;
  20. }
最佳答案
您可以增加Nginx性能,只需在config中添加下一个选项:

  1. http {
  2. open_file_cache max=1000 inactive=300s;
  3. open_file_cache_valid 360s;
  4. open_file_cache_min_uses 2;
  5. open_file_cache_errors off;
  6. }

猜你在找的Nginx相关文章