特に何もしていないのですが昨日より
502 Bad Gateway
又は
nginx error! The page you are looking for is temporarily unavailable. Please try again later.
が発生して困っております。
解決方法に心当たりのある方がいらっしゃればご教授下さいませ。
宜しくお願い致します。
###環境
AWS EC2+RDS
AMIMOTO Nginx Reverse Proxy
Wordpress
※サーバー周りは超初心者ですが、google先生に教えていただき設定しました。
###症状
0. 502エラー発生(サイトが固まっている)
0. インスタンスを再起動
0. 再起動後はサイト閲覧可能
0. すぐに固まってエラーになります。
###まず確認してみたこと
nginxとphp-fpmがタイムアウトしたり子プロセスがいっぱいになっているので設定を見直してみた。 | rhasm.net/blog
参考にさせて頂きました。
/var/log/nginx/error.logの確認
[error] 4247#0: *573 connect() to unix:/var/run/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: unix:, server: _, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "xxx.com"
◆「php-fpm.sock」とやらに問題があるのでは
htopでサーバー確認
- uptime 約15分
- Cpuは、徐々に上がり始めほぼ100%
- Mem 約70〜95%
- Load average はどんどん溜まって30台まで
- 複数のphp-fpmが実行中
◆リソースが足りなくなってエラーが発生してるよう
###PHP-FPMの設定
■エラー発生時設定
/var/log/php-fpm/error.logの確認
WARNING [pool www] server reached pm.max_children setting (5), consider raising it
□/etc/php-fpm.d/www.conf ※デフォルト
listen = /var/run/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0666 user = nginx group = nginx pm = dynamic pm.max_children = 5 pm.start_servers = 1 pm.min_spare_servers = 1 pm.max_spare_servers = 4 pm.max_requests = 200 rlimit_files = 131072 rlimit_core = unlimited request_terminate_timeout = 90 request_slowlog_timeout = 60 slowlog = /var/log/php-fpm/www-slow.log php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on php_admin_value[upload_max_filesize] = 200M php_admin_value[post_max_size] = 200M php_admin_value[max_execution_time] = 90
■/etc/php-fpm.d/www.confの修正
nginxとphp-fpmがタイムアウトしたり子プロセスがいっぱいになっているので設定を見直してみた。 | rhasm.net/blog
参考にさせて頂きました。
pm.max_children = 5 ※5=>100に変更してみる。
listen.backlog = 256 ※1行追加
###Nginxの設定
■エラー発生時設定
□/etc/nginx/nginx.conf ※デフォルト
user nginx nginx; worker_processes 2; worker_rlimit_nofile 10240; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 8192; use epoll; } 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"'; log_format backend '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent"'; access_log /var/log/nginx/access.log main; server_name_in_redirect off; server_tokens off; sendfile on; tcp_nopush off; keepalive_timeout 5; client_max_body_size 200M; client_body_buffer_size 256k; "/etc/nginx/nginx.conf" 100L, 3234C client_max_body_size 200M; client_body_buffer_size 256k; if_modified_since before; gzip on; gzip_http_version 1.0; gzip_vary on; gzip_comp_level 6; gzip_types text/plain text/xml text/css text/javascript application/xhtml+xml application/xml application/rss+xml application/atom_xml application/javascript application/x-javascript application/x-httpd-php; gzip_disable "MSIE [1-6]\."; # proxy cache proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=czone:32m max_size=256m inactive=1440m; proxy_temp_path /var/cache/nginx/proxy_temp; proxy_cache_key "$scheme://$host$request_uri"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Remote-Addr $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-UA-Detect $mobile; proxy_set_header Accept-Encoding ""; proxy_set_header X-UA-Detect $mobile; proxy_set_header Accept-Encoding ""; proxy_hide_header X-Pingback; proxy_hide_header Link; proxy_hide_header ETag; proxy_connect_timeout 5; proxy_send_timeout 10; proxy_read_timeout 90; proxy_cache_use_stale timeout invalid_header http_500 http_502 http_503 http_504; proxy_cache_lock on; proxy_cache_lock_timeout 5s; proxy_buffers 8 32k; proxy_buffer_size 64k; # fastcgi cache #fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2 # keys_zone=fastcgizone:32m inactive=60m; #fastcgi_cache_key "$scheme$request_method$host$request_uri"; #fastcgi_cache_use_stale error timeout invalid_header http_500; #limit_req_zone $request_method zone=method:1m rate=250r/s; upstream backend { server unix:/var/run/nginx-backend.sock; } upstream phpfpm { server unix:/var/run/php-fpm.sock; } include /etc/nginx/conf.d/*.conf; }
■/etc/nginx/nginx.confの修正
proxy_read_timeout 90; ※90=>300に変更してみる。
pfp-fpm、nginx再起動、
念のため、ec2も再起動
少し設定を変更しましたが今のところ効果はなしです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。