【问题标题】:Nginx and Centos OptimizationsNginx 和 Centos 优化
【发布时间】: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;

}

【问题讨论】:

    标签: linux nginx centos6


    【解决方案1】:

    检查您的 PHP FPM 池设置pm.* - http://www.php.net/manual/en/install.fpm.configuration.php

    pm.max_children int

    pm设置为static时创建的子进程数和pm设置为dynamic时创建的最大子进程数。此选项是强制性的。

    此选项设置将同时处理的请求数的限制。等效于带有 mpm_prefork 的 ApacheMaxClients 指令和原始 PHP FastCGI 中的 PHP_FCGI_CHILDREN 环境变量。

    pm.start_servers int

    启动时创建的子进程数。仅在 pm 设置为动态时使用。默认值:min_spare_servers + (max_spare_servers - min_spare_servers) / 2。 pm.min_spare_servers int

    所需的最小空闲服务器进程数。仅在 pm 设置为动态时使用。在这种情况下也是强制性的。

    pm.max_spare_servers int

    所需的最大空闲服务器进程数。仅在 pm 设置为动态时使用。在这种情况下也是强制性的。 pm.max_requests int

    每个子进程在重生之前应执行的请求数。这对于解决 3rd 方库中的内存泄漏问题很有用。对于无休止的请求处理,请指定“0”。等效于 PHP_FCGI_MAX_REQUESTS。默认值:0。

    【讨论】:

    • 嘿,我检查了两个系统的 pm.max_children = 50, pm.start_servers = 5, pm.min_spare_servers = 10, pm.max_spare_servers = 35,所以我只是为更大的系统加倍,它工作。嘿,我如何找到最好的配置?不过非常感谢。
    • 您必须查看 FPM 状态页面以获取最大侦听队列、空闲进程、活动进程、总进程、最大活动进程、达到的最大子节点、确定“最佳”配置的信息。设置诸如 Cacti cacti.net 之类的工具来自动化它。
    猜你喜欢
    • 2015-06-03
    • 2014-01-16
    • 1970-01-01
    • 2012-02-23
    • 2014-07-13
    • 1970-01-01
    • 2014-01-23
    • 2021-09-10
    • 2016-06-08
    相关资源
    最近更新 更多