Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ LNMP summary of the issues common 502 Bad Gateway     - Analysis: Little Notebook facing a major security threat secure online (Linux)

- How to modify the Sublime in Tab four spaces (Linux)

- Red Hat Enterprise Linux Server 6.5 installation GCC 4.9.2 (Linux)

- Five strokes to find out the IP address you want to know (Linux)

- Get basic information about Linux server script (Server)

- Python extension module Ganglia 3.1.x (Linux)

- Example of use WebSocket (Programming)

- OpenGL Superb Learning Notes - GLSL language foundation (Programming)

- Linux ln command - create a file / directory link (Linux)

- findmnt- Looking mounted file system (Linux)

- Oracle database on the hit rate of query summary (Database)

- How to install with JSON support in Ubuntu 15.04 SQLite 3.9.1 (Database)

- Linux Network Programming - non-blocking program (Programming)

- Recycle Bin function realization in Linux (Linux)

- How to configure MongoDB replica set (Database)

- MySQL master recovery from failure using binlog (Database)

- Linux System Getting Started Learning: From VirtualBox from the client host access NAT (Linux)

- Nginx Installation and Configuration (Server)

- Java regular expressions examples (Programming)

- Oracle conditional select statements and looping statements (Database)

 
         
  LNMP summary of the issues common 502 Bad Gateway
     
  Add Date : 2018-11-21      
         
         
         
  When we configure LNMP, 502 always encounter problems, either in the browser or use the curl command to access, it is easy to appear the "502 Bad Gateway", then what reason is wrong, there is how to solve it . According to the author summed up the experience.

Error 1: Configuration Error

We first introduce LNMP environment, by definition, LNMP environment by nginx, mysql, php composition, but nginx belongs users and groups are php-fpm, then how will nginx with php link together? Here there are two modes, one is a socket mode, the other is a tcp / ip form (or called ip: port form).

When we configure nginx virtual host configuration file has this to say:

location ~ \ .php $ {

        include fastcgi_params;

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME / data / www $ fastcgi_script_name;

}

Please note that this positive during the third row of the configuration file, I use here is ip: port of the form, what kind of when to use it? Should speak two can be. We generally default mode is the socket is connected via a socket file, and the default socket file directory is / tmp / directory, so the socket file path fastcgi_pass must write back right, otherwise there will be 502! !

If we do not generate not generated .socket files in the specified directory how to do it? This time we need to fastcgi_pass change ip: port form of attention if only to change the contents of this configuration file is still 502, we also need to change the contents of another configuration file that php configuration file: / usr / local / php / etc / php-fpm.conf, open the file we can see the following:

[Global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

[Www]

listen = 127.0.0.1:9000

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

The configuration file also listen to the same part of the ip: port form, so nginx and php to contact them, and then re

Loading nginx: /etc/init.d/nginx reload

The total sentence: in the form of these two places must be the same, or be wrong.

Error two: Permissions

We then start nginx, nginx can look at the process: ps aux | grep nginx

Then we discovered that the owner is a group of nginx worker processes are nobody

The 502 has been in order to solve problems caused wrong permission to do so, we need to profile /usr/local/php/etc/php-fpm.conf

Added two sentences:

listen.owner = nobody

listen.group = nobody

Then reload nginx

Error three: resource depletion

LNMP architecture processing php, nginx is a direct retrieval of backend php-fpm service, if the high volume of requests nginx, but we do not have enough to php-fpm configuration sub-process, then there is always a php-fpm resource depletion when, once you find the depletion nginx php-fpm, at this time will lead to 502 appear. Well, this time the solution is to adjust the value pm.max_children in php-fpm.conf to increase. But not an infinite set, after all, limited server resources, based on experience, 4G memory machine if only run php-fpm and nginx, do not run mysql service, pm.max_children can be set to 150, try not to exceed this value, 8G memory settings available 300, and so on.

Common mistake is above several, if not solve, refer to the error log, configuration files nginx.conf the error_log, adjust their level, will help us to see more mistakes.
     
         
         
         
  More:      
 
- Linux environment variable settings and save places (Linux)
- Android developers learning Adapter (data adapter) (Programming)
- The basic principles of AIX system security (Linux)
- To setup CentOS LAMP environment (Server)
- Ubuntu 12.04 installation NVIDIA GTX750 graphics driver (Linux)
- MyCAT separate read and write to achieve MySQL Practice (Database)
- Lua4.0 interpreter entrance (Programming)
- Linux Network Programming - raw socket Example: sending a UDP packet (Programming)
- System Security: Build Linux with LIDS steel castle (Linux)
- Install Gnome Flashback Classic Desktop on Ubuntu 14.10 / Mint 7 (Linux)
- Linux device driver development small example --LED lights (Programming)
- How to use the command line ftp upload and download files (Linux)
- Solve ORA-01012: not logged on (Database)
- HTML5 Application Cache (Programming)
- Android custom controls create the simplest skid menu in the history (Programming)
- Oracle study notes view (Database)
- Overall Physical Migration of Oracle Database with (Database)
- Oracle 11g dataguard main library backup and recovery to the test environment in one database error (Database)
- To install and deploy Java applications under CentOS 6.5 (Linux)
- Git uses a basic tutorial (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.