偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

純靜態(tài)文件環(huán)境下的Nginx優(yōu)化思路

原創(chuàng)
系統(tǒng) Linux
Nginx以其消耗資源少,承受并發(fā)量大,配置文件簡潔等特點,深受廣大sa們的喜歡,但是網(wǎng)上傳播的nginx配置并沒有對做過多的優(yōu)化。本文從某大型媒體網(wǎng)站的實際運維nginx優(yōu)化角度,來給大家講解一下在純靜態(tài)文件環(huán)境下nginx優(yōu)化需要考慮的一些因素。

【51CTO獨家特稿】Nginx以其消耗資源少,承受并發(fā)量大,配置文件簡潔等特點,深受廣大sa們的喜歡,但是網(wǎng)上傳播的nginx 配置并沒有對做過多的優(yōu)化。那么接下來,我就從某大型媒體網(wǎng)站的實際運維nginx優(yōu)化角度,來給大家講解一下nginx主要優(yōu)化的那些方面。

一、編譯方面優(yōu)化

1、首先就要從configure 參數(shù)分析,根據(jù)網(wǎng)上最常用的configure 參數(shù)來說,大都是

./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module  --with-http_ssl_module

應(yīng)該說這個參數(shù)是通用的,適用于各種環(huán)境的需要,比如php環(huán)境、純靜態(tài)文件環(huán)境、代理環(huán)境等等。編譯nginx程序文件大約有2M大小,跟全面優(yōu)化的500多K,相差了不少。

下面我們修改一下參數(shù),減少不必要的功能。

純靜態(tài)文件環(huán)境參數(shù)

./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module --without-http_fastcgi_module --without-http_proxy_module --without-http_upstream_ip_hash_module --without-http_autoindex_module --without-http_ssi_module   --without-http_proxy_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module  --without-http_memcached_module

去掉了在mail模塊fastcgi模塊 代理模塊 ip_hash模塊等,在純靜態(tài)文件用不到的模塊,現(xiàn)在看看nginx程序文件是不是少了一些。

Php環(huán)境的話,只需要去掉--with-http_fastcgi_module 重新編譯即可。

代理環(huán)境的話,只需要去掉--with_proxy_module重新編譯即可。

2、去掉nginx 默認(rèn)的debug跟蹤設(shè)置。這一步需要修改nginx 源碼。

cd nginx-1.0.x
vim auto/cc/gcc 

第175行

CFLAGS="$CFLAGS -g"

前面加#注釋掉改行。

這樣的話,編譯的參數(shù),就會減少到500多K的標(biāo)準(zhǔn),這樣在大并發(fā)量的條件下,性能提升明顯。

二、利用google-perftools來優(yōu)化高并發(fā)條件下的nginx

在32位系統(tǒng)下,可以直接安裝google-peftools,64位條件下,需要先安裝libunwind庫。然后再nginx configure 參數(shù)增加--with-google_perftools_module 重新編譯安裝nginx 。

這里以64位環(huán)境為準(zhǔn)

1)安裝libunwind庫

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
tar zxvf libunwind-0.99.tar.gz
cd libunwind-0.99/
CFLAGS=-fPIC ./configure –prefix=/usr
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

2)安裝google-perftools

wget http://google-perftools.googlecode.com/files/google-perftools-1.7.tar.gz
tar xzvf google-perftools-1.7.tar.gz
cd google-perftools-1.7

然后開始配置:

./configure --prefix=/usr --enable-frame-pointers (32位可以不添加--enable-frame-pointers)
make --j4 && make install

nginx configure 參數(shù)加上--with-google-perftools 重新編譯nginx

./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module --without-http_fastcgi_module --without-http_proxy_module --without-http_upstream_ip_hash_module --without-http_autoindex_module --without-http_ssi_module   --without-http_proxy_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module  --without-http_memcached_module –with-google_perftools_module 
make && make install

3、在nginx.conf 的pid部分下,增加

google_perftools_profiles /data0/google_cache;

重啟

service nginx restart

即可生效。

三、nginx 工作進(jìn)程優(yōu)化

通常的做法是在nginx.conf 的

worker_processes 8;

下面增加

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

但是在純靜態(tài)文件環(huán)境下,我們可以增加nginx 工作進(jìn)程,來提升nginx的工作效率。

工作進(jìn)程 為24個,worker_cpu_affinity 可以這樣來調(diào)整

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

重啟nginx后生效,可以充分利用nginx的對多核心cpu的良好的特性,大幅提升網(wǎng)站的訪問速度。

 

作者簡介:崔曉輝,網(wǎng)名coralzd,大眾網(wǎng)系統(tǒng)管理員,精通網(wǎng)站系統(tǒng)架構(gòu)、Unix技術(shù)。gtalk:coralzd@gmail.com

【51CTO.com獨家特稿,轉(zhuǎn)載請注明原文作者和出處?!?/p>

【編輯推薦】

  1. Cacti如何監(jiān)控Nginx運行狀態(tài)
  2. FreeBSD 8.0+Nginx+PHP配置高性能Web平臺
  3. 《Linux運維趨勢》第13期:服務(wù)器優(yōu)化

 

責(zé)任編輯:yangsai 來源: 51CTO.com
相關(guān)推薦

2010-07-23 10:42:03

2011-09-10 19:51:07

云計算云安全

2010-03-30 14:22:01

Nginx靜態(tài)文件

2016-08-29 21:36:55

nginxWeb緩存

2010-03-29 09:23:00

2010-03-25 18:09:23

Nginx配置文件

2018-12-18 09:00:26

Kubernetes工作負(fù)載測試

2023-06-23 15:22:28

JettyJava

2011-07-18 18:01:34

buffer cach

2010-01-08 09:43:40

Ubuntu ngin

2013-06-05 13:31:25

2022-03-02 11:13:50

Web前端開發(fā)

2024-09-26 13:11:07

2011-09-08 11:02:39

Web2.0網(wǎng)康

2020-03-23 22:50:36

WindowsNginxTomcat

2012-12-27 10:15:13

金融行業(yè)

2012-04-25 09:24:17

Java

2009-12-09 13:23:24

靜態(tài)路由配置

2010-07-27 14:25:02

linux文件編碼

2021-03-15 09:27:05

Redis優(yōu)化技術(shù)
點贊
收藏

51CTO技術(shù)棧公眾號