首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx PHP-FPM问题

Nginx PHP-FPM问题
EN

Stack Overflow用户
提问于 2015-06-24 10:53:44
回答 1查看 289关注 0票数 0

我们最近从apache迁移到nginx。

代码语言:javascript
复制
OS - CetnOS 6
Nginx - 1.62 (4 CPU 8 GB RAM)
PHP-FPM (php 5.4.37) (4 CPU 8 GB RAM)
APC (Code Cache APC 3.1.13 beta)
Memcache (data cache)
Soft File Limit - 300000 (/etc/security/limits.conf)
Hard File Limit - 300000

根据建议修改sysctl TCP配置。

我有上游的4 php服务器的php服务。

我面临两个问题:

  1. 我在访问日志中获得502状态代码,这意味着nginx会产生502个错误的网关错误。
  2. 随机连接在nginx上堆积到2500,在php-fpm服务器上,我们没有看到顶部有任何负载,只有1-2进程在这段时间内似乎在运行,如果在2-3分钟后不重新启动,它就开始正常工作,连接在没有重新启动的情况下就会恢复正常。

请检查nginx的在线配置。

代码语言:javascript
复制
user nguser;
worker_processes 4;

pid /var/run/nginx.pid;
worker_rlimit_nofile 70000;

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

http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_requests 1000;
keepalive_timeout 65;
send_timeout 15;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 50M;
client_body_buffer_size 1m;
client_body_timeout 15;
client_header_timeout 15;
server_names_hash_bucket_size 64;
server_name_in_redirect off;

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

##
# Logging Settings
##
#access_log on;

access_log /var/log/nginx/access.log combined;
#error_log /dev/null crit;
error_log /var/log/nginx/error.log error;


#gzip on;
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 512;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/css text/javascript text/xml text/plain text/x-component
application/javascript application/x-javascript application/json
application/xml application/rss+xml font/truetype application/x-font-ttf
font/opentype application/vnd.ms-fontobject image/svg+xml;

open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;

fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_intercept_errors on;
reset_timedout_connection on;

upstream fastcgiservers {
least_conn;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
}

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

location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass fastcgiservers;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

设置

代码语言:javascript
复制
pm.max_children = 150
pm.start_servers = 90
pm.min_spare_servers = 70
pm.max_spare_servers = 100
pm.max_requests = 1500

如有任何帮助或建议,将不胜感激。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-06-24 17:05:51

移除和替换

代码语言:javascript
复制
    fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_intercept_errors on;
reset_timedout_connection on;

upstream fastcgiservers {
least_conn;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
server xxx.xxx.xx.xx:9000;
}

以这种方式替换

代码语言:javascript
复制
server {
  location / {
    proxy_pass  http://backend;
  }
}

upstream backend  {
  server backend1.example.com;
  server backend2.example.com;
  server backend3.example.com;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31024648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档