502 005_ common errors

Common mistakes 502

1. configuration error

Because nginx php-fpm not found, so the error is generally arranged behind the fastcgi_pass wrong path, it can be followed by a socket or ip: port;

2. Resource depletion

lnmp architecture when dealing with php, nginx direct retrieval of the back-end php-fpm services, if requested amount of nginx high, we do not have enough to php-fpm configuration of the child, then the php-fpm resources will be depleted once resource depletion nginx php-fpm will not find 502 errors;

Solution:
to adjust the value pm.max_children php-fpm.conf in, it increases, but can not increase indefinitely, after all, limited resources, general 4G memory machine if running php-fpm and nginx, do not run mysql can be set to 150 , 8G 300 and so on;

3. Other reasons

In addition there are other reasons for the above two errors, rarely have, we can help troubleshoot the nginx error log:

cat /usr/local/nginx/logs/nginx_error.log

We can also define the level to the log: vim / usr / local / nginx / conf / nginx.conf find error_log, the default is the most rigorous crit on the line, you can also change the display of the most comprehensive debug information, but it is easy to explode our disk.

3.1 modify nginx configuration file

First, we need to allow browser access

vim/usr/local/nginx/conf/vhosts/111.conf

server
{
   listen 80;
   server_name www.111.com;       // 域名地址
   index index.html index.htm index.php;
   root /data/www/;
   location ~ \.php$ {
       include fastcgi_params;
       fastcgi_pass unix:/tmp/www.sock;  // 修改sock
      #fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
    }
}

3.2 Check grammar is normal

/usr/local/nginx/sbin/nginx -t

3.3 reload the configuration file

/usr/local/nginx/sbin/nginx-s reload

/etc/init.d/nginx reload

3.4 check which user is running nginx

ps aux |grep nginx

3.5 edit php-fpm file

We want to set the user's home nginx php-fpm in this document which, with the group so as not to display 502

vim/usr/local/php/etc/php-fpm.conf

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log =/usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/www.sock
user = php-fpm
group = php-fpm
listen.owner = nobody    //定义属主
listen.group = nobody    //定义属组
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

3.6 restart php-fpm

/etc/init.d/php-fpm restart

Added: Recent problems encountered by many students
in this case, using a socket, higher than version 5.4 (including 5.4) default file permissions listening socket is the owner read-only, and the other is a group of users without any permission. So, nginx launch customer (our configuration is nobody) there is no way to read the socket file, resulting in 502, this problem can be found in the nginx error log. The solution is simple, given the profile of the above configuration will have to avoid this problem.

listen.owner = nobody    //定义属主
listen.group = nobody    //定义属组

These two configuration is defining who socket of the owner and group Yes. In addition to this there is a way

listen.mode = 666

So nobody can have the read permission.

Guess you like

Origin www.cnblogs.com/cy-8593/p/12333631.html