NGINX适用于100K + R / S.

时间:2015-10-03 01:47:46

标签: optimization nginx server webserver

我正在尝试调整NGINX以获得INSANE流量。

我有一个庞大的专用服务器,我的网站在流量非常高的时候一直在下降。

虽然当我检查顶部时,我几乎看不到CPU使用情况。

如何增加NGINX使用的CPU数量?

这是我当前的nginx配置

user www-data;
worker_processes 16;
worker_rlimit_nofile 819200;
pid /var/run/nginx.pid;


events {
    worker_connections 161920;
    # multi_accept on;
    use epoll;
    multi_accept on;
}

http {
# set client body size to 2M #
client_max_body_size 2M;
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 15;
    types_hash_max_size 8096;
    # server_tokens off;

    server_names_hash_bucket_size 256;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

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


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

1 个答案:

答案 0 :(得分:1)

如果您有超过16个核心,则可以增加worker_process。 查看:https://www.nginx.com/blog/tuning-nginx/

但是,你确定它是由于CPU利用率而不是RAM或其他东西(比如你的应用程序)而崩溃了吗?确保检查错误日志并收集指标,因为如果它与CPU负载有关,我会感到惊讶(特别是基于你所说的)。我建议像Munin(http://munin-monitoring.org)这样的东西来收集可靠的指标,并试图更好地弄清楚究竟发生了什么。