A detailed approach to small VPS optimization Nginx PHP-FPM

Source: Internet
Author: User
Tags fpm vps

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 43 118
-/+ buffers/cache:453 540
swap:0 0 0

[Root@xxxxxx nginx]# Cat/proc/cpuinfo
processor:0
Vendor_id:genuineintel
CPU Family:6
model:62
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:13
Wp:yes
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC .... Omitted....
bogomips:5188.04
Clflush size:64
Cache_alignment:64
Address sizes:46 bits physical, bits virtual
Power Management:

Second, PHP-FPM optimization


PM = dynamic//Number of processes, dynamically allocated
Pm.max_children = 24//maximum number of processes
Pm.start_servers = 8//number of processes when just started
Pm.min_spare_servers = 8//minimum number of processes when the server is idle
Pm.max_spare_servers = 24//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; Setting up Auto,nginx process dynamic allocation

# Access_log//comment out, reduce I/O
# Log_format//comment out, reduce I/O

gzip on; Turn on 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

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.