【发布时间】:2014-03-01 07:44:11
【问题描述】:
我已经在两台不同的机器上安装并优化了 nginx。 Machine1:具有 2 个 CPU 和相当低的系统资源。 Machine2:具有 4 个 CPU 和更高的系统资源。
但它们仍然在大约相同数量的请求时失败。也许还有其他东西限制了服务器,可能是一些操作系统设置,而不一定是 nginx 设置。
我在 CentOS -6.3 上使用 php-fpm 设置了 nginx。我在两个系统中都增加了 ulimit -n 值。
这是我的 nginx.conf
user nginx;
worker_processes 2;
worker_rlimit_nofile 16384;
error_log /var/log/nginx/error.log crit;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 5000;
# essential for linux, optmized to serve many clients with each thread
use epoll;
multi_accept on;
}
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;
access_log off;
sendfile on;
tcp_nopush on;
server_tokens off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
#keepalive_timeout 0;
keepalive_timeout 65;
keepalive_requests 100000;
gzip on;
gzip_proxied any;
gzip_min_length 256;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
}
【问题讨论】: