nginx php-fpm 小VPS 最佳化_nginx

來源:互聯網
上載者:User

小VPS受系統資源的限制,訪問量過大,超過系統所能承受的極限時,有一部分請求就會502了。在系統資源夠用的情況,最佳化nginx,php-fpm,以及系統本身,達到2個目的:

1,合理配置系統資源,將有限的資源,最大化利用。好鋼用在刀刃上。

2,盡量減少磁碟的I/O

一,系統主要資源

[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 。。。。省略。。。。  bogomips    : 5188.04  clflush size  : 64  cache_alignment : 64  address sizes  : 46 bits physical, 48 bits virtual  power management: 

二,php-fpm最佳化

pm = dynamic           //進程數,動態分配pm.max_children = 24       //最大進程數pm.start_servers = 8       //剛啟動時的進程數pm.min_spare_servers = 8     //伺服器空閑時的最小進程數pm.max_spare_servers = 24     //伺服器空閑時的最大進程數php_flag[display_errors] = off  //運行一段時間後,將錯誤提示資訊關閉掉

php-fpm一個進程佔了20M-30M之間,top看一下php-fpm占的記憶體百分比,估算一下就知道了。max_children,max_spare_servers不是越大越好。

三,nginx最佳化

1,安裝穩定最新版

# vim /etc/yum.repos.d/nginx.repo  //加上以下內容[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1# yum install nginx   //更新nginx

2,最佳化配置nginx

worker_processes auto;   //設定auto,nginx進程動態分配# access_log  //注釋掉,減少I/O# log_format  //注釋掉,減少I/Ogzip on;     //開啟gzipgzip_min_length 1k;gzip_buffers   4 16k;gzip_http_version 1.1;gzip_comp_level 5;    //1-9,越大壓縮越好,消耗資源越大gzip_types    text/plain application/x-javascript text/css application/xml;gzip_vary on;

worker_processes對於小VPS的話,設成1,2也是可以的。夠用了。

對於小vps的話,上面nginx,php-fpm的最佳化配置都是有益的。

四,linux啟動進程最佳化

複製代碼 代碼如下:

# chkconfig --list |grep on

查看開機啟動的進程,把不必要啟動進程關掉。如果遇到不知道的,最好先查一下在決定要不要關閉。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.