V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Mask0c
V2EX  ›  程序员

Nigx 环境下在服务器使用率不到 20% 网站就 504 gateway time-out,以贴环境。

  •  
  •   Mask0c · 2017-08-05 00:59:16 +08:00 · 2088 次点击
    这是一个创建于 2695 天前的主题,其中的信息可能已经有所发展或是发生改变。

    nginx.conf 的配置内容

    user www www;

    worker_processes auto;

    error_log /dzdata/wwwlogs/error_nginx.log crit; pid /var/run/nginx.pid; worker_rlimit_nofile 65535;

    events { use epoll; worker_connections 65535; multi_accept on; }

    http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 1024m; client_body_buffer_size 10m; sendfile on; tcp_nopush on; keepalive_timeout 120; server_tokens off; tcp_nodelay on;

    fastcgi_connect_timeout 2400; fastcgi_send_timeout 2400; fastcgi_read_timeout 2400; fastcgi_buffer_size 512k; fastcgi_buffers 4 512k; fastcgi_busy_buffers_size 1024k; fastcgi_temp_file_write_size 1024k; fastcgi_intercept_errors on;

    Gzip Compression# gzip on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/javascript application/javascript application/x-javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype application/x-font-ttf application/vnd.ms-fontobject image/x-icon; gzip_disable "MSIE [1-6].(?!.*SV1)";

    If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.# open_file_cache max=65535 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on;

    ######################## default ############################ server { listen 80; servername ; access_log /dzdata/wwwlogs/access_nginx.log combined; root /dzdata/wwwroot/default; index index.html index.htm index.php;

    error_page 404 /404.html;# #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } location ~ [^/].php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ ..(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ ..(js|css)?$ { expires 7d; access_log off; } location ~ /.ht { deny all; } } ########################## vhost ############################# include vhost/*.conf; }

    php-fpm.conf 配置内容

    ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;;

    ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;;

    [global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = warning

    emergency_restart_threshold = 30 emergency_restart_interval = 60s process_control_timeout = 5s daemonize = yes

    ;;;;;;;;;;;;;;;;;;;; ; Pool Definitions ; ;;;;;;;;;;;;;;;;;;;;

    [www] listen = /dev/shm/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www

    pm = dynamic pm.max_children = 192 pm.start_servers = 144 pm.min_spare_servers = 96 pm.max_spare_servers = 192 pm.max_requests = 4096 pm.process_idle_timeout = 10s request_terminate_timeout = 900 request_slowlog_timeout = 0

    pm.status_path = /php-fpm_status slowlog = log/slow.log rlimit_files = 51200 rlimit_core = 0

    catch_workers_output = yes ;env[HOSTNAME] = CTS5001 env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp#

    服务器的配置 CPU: Intel Xeon E5-2650*2 硬盘: 525GB SSD 内存: 64GB DDR3 ECC 网络环境:G 口独享 CN2 线路 阿里云的 CDN#

    服务器系统是 centos 6.7 PHP7.1 + Redis 4.0.1 Mysql 5.5.2

    PHP 线程:12000+的时候就挂了#

    服务器就 504 gateway time-out#

    求大神给个解决方法! TAT 很难过。

    3 条回复
    linkermlin
        1
    linkermlin  
       2017-08-05 01:29:37 +08:00
    PHP 线程数目太多了。
    Mask0c
        2
    Mask0c  
    OP
       2017-08-05 03:05:41 +08:00
    @linkermlin 应该如何进行 PHP 的优化?让 php 的线程快速处理释放。
    mchl
        3
    mchl  
       2017-08-05 07:07:13 +08:00 via Android
    PHP 上 opcache 了吗,提升会很明显
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2872 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:34 · PVG 14:34 · LAX 22:34 · JFK 01:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.