Small VPS is limited by the system resources, the traffic is too large, more than the system can withstand the limit, a part of the request will be 502. In the case of adequate system resources, optimizing NGINX,PHP-FPM, as well as the system itself, achieves 2 purposes:
1, reasonable allocation of system resources, the limited resources to maximize utilization. Good steel is used on the blade.
2, minimizing disk I/O
First, the system main resources
[Root@xxxxxx nginx]# free-m
total used free shared buffers cached
Mem: 994 815 179 0 118
-/+ buffers/cache: 453 540
Swap: 0 0 0
[root@xxxxxx nginx]# cat/proc/cpuinfo
processor : 0
vendor_id : Genuineintel
CPU Family : 6
model : The
model name : Intel (R) Xeon (r) CPU e5-2650 v2 @ 2.60GHz
Stepping : 4
CPU MHz : 2594.024
Cache size : 20480 KB
physical ID : 0
siblings : 1
Core ID : 0
CPU Cores : 1
apicid : 0
initial apicid:0
FPU : Yes
Fpu_exception : Yes
cpuid level :
WP : yes
flags : FPU VME de PSE TSC MSR PAE MCE CX 8 APIC .... Omitted....
bogomips : 5188.04
clflush size :
cache_alignment:64 Address
sizes : + bits Physical, bits virtual
Second, PHP-FPM optimization
PM = Dynamic//number of processes, dynamically allocated
Pm.max_children = Max//maximum number
of processes pm.start_servers = 8//number of processes just started
Pm.min_ Spare_servers = 8 //The minimum number of processes when the server is idle
pm.max_spare_servers = Maximum number of processes when the server is idle
php_flag[display_errors = off//run for a period of time, turn off the error message
PHP-FPM a process takes up between 20m-30m, top look at the percentage of memory in PHP-FPM, the estimate will know. Max_children,max_spare_servers not bigger is better.
Third, nginx optimization
1, install the latest version of stability
# Vim/etc/yum.repos.d/nginx.repo //Add the following content
[Nginx]
name=nginx repo
baseurl=http://nginx.org/ packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
# yum install nginx /update Nginx
2, optimize configuration Nginx
Worker_processes Auto; Set Auto,nginx process dynamic Allocation
# Access_log //comment out, reduce I/O
# log_format //comment out, reduce I/O
gzip on; Open gzip
gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_http_version 1.1;
Gzip_comp_level 5; 1-9, the greater the compression the better, the greater the consumption of resources
gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Worker_processes for small VPS, set to 1, 2 is also possible. It's enough.
For small VPS, the above NGINX,PHP-FPM optimization configuration is beneficial.
Four, Linux boot process optimization
Copy Code code as follows:
# chkconfig--list |grep on
View the boot-initiated process and turn off the process without the need to start. If you do not know, it is best to check before deciding whether to close.