If you encounter a 502 problem in nginx, you can take the following two steps as a priority.
1. Check whether the current PHP FastCGI Process count is sufficient:
The code is as follows: |
Copy code |
Netstat-anpo | grep "php-cgi" | wc-l |
If the number of FastCGI processes actually used is close to the preset number of FastCGI processes, it indicates that the number of FastCGI processes is insufficient and needs to be increased.
2. If the execution time of some PHP programs exceeds the Nginx waiting time, you can add the FastCGI timeout time in the nginx. conf configuration file, for example:
The code is as follows: |
Copy code |
...... Http { ...... Fastcgi_connect_timeout 300; Fastcgi_send_timeout 300; Fastcgi_read_timeout 300; ...... } ...... |
In php. ini, if memory_limit is set to low, an error will occur. After modifying memory_limit of php. ini to 64 MB, restart nginx and check that PHP memory is insufficient.
My VPS architecture is lnmp solution:
Using Nginx to limit the number of concurrent connections of a single IP address can reduce the number of collection programs or DDOS attacks.
Some code has been added to nginx configuration of lnmp, but it is commented out. You can edit the/usr/local/nginx/conf/nginx. conf file.
Search:
The code is as follows: |
Copy code |
# Limit_zone oneip $ binary_remote_addr 10 m;
|
Remove the previous #. If this line does not exist, add
The code is as follows: |
Copy code |
Limit_zone oneip $ binary_remote_addr 10 m;
|
Add
The code is as follows: |
Copy code |
Limit_conn oneip 20; |
The number at the end of the limit_conn statement is the maximum number of concurrent connections of a single IP address.
The code is as follows: |
Copy code |
If it is not lnmp installed, it is also very easy to add in nginx. conf Limit_zone oneip $ binary_remote_addr 10 m; Limit_conn oneip 20; |
Of course, the limit_conn oneip 20 statement can also be added to the server segment to only limit the number of virtual hosts.
Limit the number of concurrent connections directly in the server segment by adding limit_rate 100 k;
The speed of each connection is limited to 100 kB. This limit is for a single thread. For example, if I use IE to download 100 kB, it will occupy 2 threads when I use thunder, therefore, the downloading speed of Thunder is 200 kb. If the concurrency of a single IP address is set to 20, the speed of multi-thread downloading can reach KB × 20.
Restart nginx.