Nginx + php-fpm配置.服务器上


nginx + php-fpm configuration. Server stalls

运行一个每天有14万浏览量的服务器(分析)。php-fpm进程每个大约需要10-12M。
服务器有10G内存,mysql为1.2G-1.6G

配置如下:

nginx
user  nginx;
worker_processes  4;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

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;
    keepalive_timeout  10;
    client_max_body_size 20M;
        server_tokens off;
    include /etc/nginx/conf.d/*.conf;
}

php-fpm如下:

listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = webadmin
group = webadmin
pm = dynamic
pm.max_children = 900
pm.start_servers = 900
pm.min_spare_servers = 200
pm.max_spare_servers = 900
pm.max_requests = 500
chdir = /

通常情况下,服务器可以运行得很好,同时有500个用户(再次,实时谷歌分析用来得到这个估计),但当用户不是那么多(75-100个同时用户)时,服务器会停机。

配置是由我信任的ISP完成的,但我仍然想知道配置是否有意义。

我不是说这是最好的设置,但它适用于我们。

我在nginx设置中更新了一些东西:

worker_connections,我相信浏览器每个请求打开两个连接,所以你不是每个请求有1024个可用连接,你有512个,所以也许把它改成2048。

我还将错误日志文件参数更改为"info",因为您需要考虑写时间以保持I/O低,所以我将其从"warn"更改为"info"。

如果您想保留访问日志,可以减少它添加的日志总数。

可能值得看看你的主nginx.conf,你可能有配置被这个文件覆盖,并被设置回默认值。

只是我从一大堆清单中做的两件小事,但是这篇文章很棒-链接