【发布时间】:2011-11-09 21:08:38
【问题描述】:
我们的生产服务器有 Ubuntu 9.x, 内存 8GB,HDD 250Gb 使用 nginx 作为网络服务器。 我们目前在高峰时段遇到性能问题(1000 个请求/秒) 我希望服务器可以提供 1000 个请求/秒,有人可以告诉我我应该对 nginx 配置进行哪些更改。谢谢
这里是 nginx 配置文件
#user nobody;
worker_processes 8;
events {
worker_connections 8024;
}
http {
passenger_root /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/passenger-3.0.9;
passenger_ruby /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby;
passenger_pool_idle_time 0;
passenger_max_pool_size 15;
include mime.types;
default_type application/octet-stream;
sendfile on;
## General options
#ignore_invalid_headers on;
keepalive_requests 2000;
#recursive_error_pages on;
#server_name_in_redirect off;
#server_tokens off;
## TCP options
tcp_nodelay on;
tcp_nopush on;
## Timeouts
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 65;
#send_timeout 10;
#expires 24h;
gzip on;
server {
listen 80;
server_name resumecompanion.com;
passenger_enabled on;
rails_env production;
root /var/www/resumecompanion.com/production/current/public;
#access_log off;
#error_log off;
## Redirect from www to non-www
if ($host = 'www.resumecompanion.com' ) {
rewrite ^/(.*)$ http://resumecompanion.com/$1 permanent;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# HTTPS server
#
server {
listen 443;
server_name resumecompanion.com;
passenger_enabled on;
rails_env production;
ssl on;
ssl_certificate /opt/nginx/ssl/resumecompanion.com.crt;
ssl_certificate_key /opt/nginx/ssl/start_resumecompanion_com.key;
ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
root /var/www/resumecompanion.com/production/current/public;
}
}
【问题讨论】:
-
对于带有 8 个 worker_processes 的 8024 worker_connections,您还需要修改内核参数:ulimit -n 64192 (8*8024)。最好将进程数设置为与cpu核心数相等。
-
@petermolnar 也可以使用 Nginx 中的 worker_rlimit_nofile 来完成。
标签: ruby-on-rails ruby nginx webserver