Answer the question
In order to leave comments, you need to log in
Error 502 periodically crashes - nginx, where to dig?
Good day. On Monday the problem started.
When performing actions on behalf of an authorized user (posting articles to the site), an error 502 appears. Not always, every other time. After what actions it appears, I could not find out. After that, this also happened. Below are
nginx.cfg configs
user nginx nobody;
worker_processes 16;
error_log /var/log/nginx/error_log notice;
events {
## worker_connections 2048;
worker_connections 204800;
use epoll;
}
#worker_rlimit_nofile 32768;
worker_rlimit_nofile 327680;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream fpm-sock {
server unix:/var/run/php5-fpm.sock;
}
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
#geoip_country /usr/share/GeoIP/GeoIP.dat;
#geoip_city /usr/share/GeoIP/GeoIPCity.dat;
#geoip_org /usr/share/GeoIP/GeoIPISP.dat;
## Size Limits
keepalive_timeout 6000;
output_buffers 32 512k;
sendfile_max_chunk 128k;
postpone_output 1460;
server_names_hash_bucket_size 64;
client_max_body_size 100m;
## General Options
ignore_invalid_headers on;
sendfile on;
upload_progress uploads 1m;
## TCP options
tcp_nodelay on;
tcp_nopush on;
reset_timedout_connection on;
## Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 5;
gzip_http_version 1.0;
gzip_min_length 1000;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
gzip_static on;
gzip_proxied any;
gzip_disable msie6;
index index.php index.html;
include hosts/mysite.ru.conf;
...(здесь ещё 12 сайтов)
include hosts/mysite-n.ru.conf;
}# end of http
server {
listen ***.**.**.**;
server_name mysite.ru;
#limit_conn one 60;
access_log /var/log/nginx/mysite.access_log main;
error_log /var/log/nginx/mysite.error_log info;
root /var/www/mysite.ru/htdocs;
## www. redirect
if ($host ~* ^(www\.)(.+)) {
set $rawdomain $2;
rewrite ^/(.*)$ http://$rawdomain/$1 permanent;
}
## rewrite rules for old site
rewrite ^/art([0-9]*)\.html? /node/$1 permanent;
rewrite ^/topic([0-9]*)\.html? /taxonomy/term/$1 permanent;
rewrite ^/topic([0-9]*)-([0-9]*)\.html? /taxonomy/term/$1?page=$2 permanent;
rewrite ^/reviews\.php /taxonomy/term/19 permanent;
rewrite ^/theme([0-9]*)\.html? /old/theme.php?id=$1;
rewrite ^/delivery_full_([0-9]*)\.html? /old/delivery.php?d=$1;
rewrite ^/review([0-9]*)\.html? /old/review.php?id=$1;
rewrite ^/show_review\.php /old/review.php;
rewrite ^/archive\.php /archive/today permanent;
rewrite ^/yandex.news/yandex.phtm /yandex.xml;
rewrite ^/img/([^\.]*\.(jpg|gif)) /sites/default/files/img/$1 permanent;
rewrite ^/info/(.*)\.htm /info/index.php?id=$1;
rewrite ^/info/?$ /info/index.php;
rewrite ^/info/sitemap.xml /info/sitemap.php;
rewrite ^/egadget([1-9])\.xml /egadget/$1/feed permanent;
if ($request_uri ~* "^/show_article\.php\?id=([0-9]*)") {
set $q $1;
set $args "";
rewrite ^\/.*$ /node/$q permanent;
}
# location ~* ^/(bank|nojob|pkuda|politi[ck]a|shkola)/? {
location ~* ^/(nojob|pkuda|shkola)/? {
proxy_pass [url]http://old.mysite.ru;[/url]
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* ^/(medi[ck])/? {
proxy_pass [url]http://med.mysite.ru;[/url]
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
## 6.x starts
location / {
#rewrite ^/(.*)/$ /$1 permanent; # remove trailing slashes - disabled
try_files $uri @cache;
}
location @cache {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @drupal;
add_header Expires epoch;
add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
try_files /cache/normal/$host${uri}_$args.html @drupal;
}
location @drupal {
###
### now simplified to reduce rewrites
###
rewrite ^/(.*)$ /index.php?q=$1 last;
}
location ~* (/\..*|settings\.php$|\.(htaccess|engine|inc|info|ini|install|module|profile|pl|po|pot|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(Entries.*|Repository|Root|Tag|Template))$ {
deny all;
}
location ~* /files/.*\.php$ {
return 444;
}
location ~* /themes/.*\.php$ {
return 444;
}
location ~* \.php$ {
try_files $uri @drupal; #check for existence of php file
fastcgi_pass fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mysite.ru/htdocs$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.css$ {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @uncached;
access_log off;
expires max; #if using aggregator
try_files /cache/perm/$host${uri}_.css $uri =404;
}
location ~ \.js$ {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @uncached;
access_log off;
expires max; #if using aggregator
try_files /cache/perm/$host${uri}_.js $uri =404;
}
location ~ \.json$ {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @uncached;
access_log off;
expires max; #if using aggregator
try_files /cache/normal/$host${uri}_.json $uri =404;
}
location @uncached {
access_log off;
expires max; # max if using aggregator, otherwise sane expire time
}
location ~* /files/imagecache/ {
access_log off;
try_files $uri @drupal; #imagecache support - now it works
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
access_log off;
expires 30d;
try_files $uri =404;
}
location ~* \.xml$ {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @drupal;
add_header Expires epoch;
add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
types { }
default_type application/rss+xml;
try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html $uri @drupal;
}
location ~* /feed$ {
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID") {
return 405;
}
error_page 405 = @drupal;
add_header Expires epoch;
add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
types { }
default_type application/rss+xml;
try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html $uri @drupal;
}
location /rest/ {
allow 127.0.0.1;
allow ***.***.**.0/24;
allow ***.**.***.**;
deny all;
rewrite ^/(.*)$ /index.php?q=$1 break;
include cors-nginx.conf;
fastcgi_pass fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mysite.ru/htdocs$fastcgi_script_name;
include fastcgi_params;
}
} # end of server
[27-Apr-2016 10:53:02.134969] NOTICE: pid 9079, fpm_event_loop(), line 367: ready to handle connections
[27-Apr-2016 10:53:03.135992] DEBUG: pid 9079, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 3 active children, 29 spare children, 32 running children. Spawning rate 1
[B]2016/04/26 12:01:21 [info] 17564#0: *60409567 recv() failed (104: Connection reset by peer) while sending to client, client: 52.90.204.194, server: mysite.ru, request: "GET ссылка HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock", host: "mysite.ru"[/B]
насколько я понимаю это и есть та ошибка, которая мне покоя не даёт
...
2016/04/26 12:01:25 [info] 17570#0: *60408601 client 195.93.246.156 closed keepalive connection (104: Connection reset by peer)
...
2016/04/26 12:01:27 [info] 17565#0: *60409629 client 164.132.161.86 closed keepalive connection
2016/04/26 12:01:27 [info] 17564#0: *60409573 client 31.13.144.8 closed keepalive connection (104: Connection reset by peer)
2016/04/26 12:01:27 [warn] 17565#0: *60409651 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/fastcgi/3/57/0000981573 while reading upstream, client: 88.198.38.111, server: mysite.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mysite.ru"
2016/04/26 12:01:28 [info] 17565#0: *60409649 client 157.55.39.40 closed keepalive connection
...
Answer the question
In order to leave comments, you need to log in
nginx throws a 502 error when the backend is unavailable
, in particular, the first thing you would do is check the permissions on /var/run/php5-fpm.sock - for the nginx user
Restrictions should be looked for in the www.conf pool config for php-fpm.
what is the value of pm.max_children ? it may need to be enlarged...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question