LEMP鏋勫緩楂樻€ц兘WEB鏈嶅姟鍣¨
鐩綍
鍓嶈█锛
涓€銆佺郴缁熷畨瑁
1.聽绯葷粺鍒嗗尯
2.绯葷粺鍒濆鍖栬剼鏈?鏍規嵁鍏蜂綋闇€姹傚叧闂笉闇€瑕佺殑鏈嶅姟)
浜屻€佺紪璇戝畨瑁呭熀鏈幆澧
1.聽瀹夎鍑嗗
2.聽缂栬瘧瀹夎杞歡鍖
涓夈€佺紪璇戝畨瑁匬HP鍙奛ginx
1.PHP(Fastcgi)缂栬瘧瀹夎
2.瀹夎Nginx
鍥涖€丯ginx澶氳櫄鎷熶富鏈洪厤缃強鍩烘湰浼樺寲(浠ラ厤缃瓺iscuz!璁哄潧涓轟緥)
1.閰嶇疆Nginx铏氭嫙涓繪満(闃茬洍閾懼強expires璁劇疆)
2.Nginx鎼緩涓嬭澆绔欑偣闄愬埗骞跺彂鏁闆拰閫熺巼.
3.濡備綍瀹炵幇Nginx韬喚楠岃瘉
4.濡備綍瀹炵幇Nginx鐩綍鍒楄〃
5.淇敼Nginx鐨刪eader浼鏈嶅姟鍣
6.鍑忓皬nginx缂栬瘧鍚庣殑鏂囦歡澶у皬
7.Nginx鏃ュ織澶勭悊
浜斻€佸熀鏈畨鍏ㄨ缃瓥鐣
鍏€侀檮褰曞強鐩稿叧浠嬬粛
鏈枃鍩轟簬step聽by聽step鐨勭粨鏋勫悜澶у浠嬬粛Nginx鏋勫緩楂樻€ц兘WEB鐨勫叏杩囩▼.骞朵笖鎴戜滑鍦
鐢熶駭鏈嶅姟鍣ㄤ笂杩愯涓€涓湀闈炲父绋沖畾锛屾墍浠ユ暣鐞嗗嚭鏉ヤ緵澶у鍒嗕韓銆傚笇鏈涜兘澶熷府鍔
鏇村鐨勫垵瀛﹁€呰交鏉炬瀯寤洪珮鎬ц兘鐨刉EB鏈嶅姟鍣ㄣ€傚鏂囦腑鎻愬埌鐨勭浉鍏蟲搷浣滄湁浠諱綍闂閮藉彲浠
鍒癓inuxTone璁哄潧鍘諱氦娴佹彁闂紝鎴戜滑灏嗙涓€鏃堕棿涓轟綘瑙g瓟锛屽悓鏃舵妸缃戝弸鐨勫緩璁姞鍏ワ紝鍙
鏃舵洿鏂扮浉鍏沖唴瀹?
绯葷粺鐜:
CentOS聽5.1+nginx-0.6.31+php-5.2.6+memcache-2.2.3+xcache-1.2.2+mysql-5.0.51b
/boot聽100M宸﹀彸
SWAP聽鐗╃悊鍐呭瓨鐨?鍊?濡傛灉浣犵殑鐗╃悊鍐呭瓨澶т簬4G浠ヤ笂锛屽垎閰?G鍗沖彲)
/聽鍒嗗尯15~20G
/usr/local聽20G聽(鐢ㄤ簬瀹夎杞歡)
/data聽鍓╀綑鎵€鏈夌┖闂
*鍏蜂綋鍒嗗尯璇鋒牴鎹浉鍏充笟鍔″垝鍒嗭紝鍏蜂綋瀹夎鏈枃涓嶄綔浠嬬粛.
#vi聽init.sh
#welcome
cat聽<<聽EOF
+--------------------------------------------------------------+
|聽===聽Welcome聽to聽CentOS聽System聽init聽===聽|
+--------------http://www.linuxtone.org------------------------+
+--------------------------------------------------------------+
EOF
#disable聽ipv6
cat聽<<聽EOF
+--------------------------------------------------------------+
|聽===聽Welcome聽to聽Disable聽IPV6聽===聽|
EOF
echo聽"alias聽net-pf-10聽off"聽>>聽/etc/modprobe.conf
echo聽鈥渁lias聽ipv6聽off鈥澛?gt;>聽/etc/modprobe.conf
/sbin/chkconfig聽鈥搇evel聽35聽ip6tables聽off
echo聽鈥渋pv6聽is聽disabled!鈥
#disable聽selinux
sed聽-i聽鈥?SELINUX/s/enforcing/disabled/鈥櫬?etc/selinux/config
echo聽鈥渟elinux聽is聽disabled,you聽must聽reboot!鈥
#vim
sed聽-i聽鈥?聽s/^/alias聽vi=鈥檝im鈥?鈥澛?root/.bashrc
echo聽鈥檚yntax聽on鈥櫬?gt;聽/root/.vimrc
#LANG=en
sed聽-i聽-e聽鈥檚/^LANG=.*/LANG=鈥漞n鈥?鈥櫬?etc/sysconfig/i18n
#tunoff聽services
#鈥斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€?
|聽===聽Welcome聽to聽Tunoff聽services聽===聽|
#--------------------------------------------------------------+
for聽i聽in聽`ls聽/etc/rc3.d/S*`
do
CURSRV=`echo聽$i|cut聽-c聽15-`
echo聽$CURSRV
case聽$CURSRV聽in
crond聽|聽irqbalance聽|聽microcode_ctl聽|聽network聽|聽random聽|聽sendmail聽|聽sshd聽|聽syslog聽|聽local聽|聽mysqld聽)
echo聽"Base聽services,聽Skip!"
;;
*)
echo聽"change聽$CURSRV聽to聽off"
chkconfig聽--level聽235聽$CURSRV聽off
service聽$CURSRV聽stop
esac
done
#sh聽init.sh聽(鎵ц涓婇潰淇濆瓨鐨勮剼鏈紝浠嶅悗閲嶅惎)
1)聽绯葷粺绾﹀畾
杞歡婧愪唬鐮佸寘瀛樻斁浣嶇疆聽/usr/local/src
婧愮爜鍖呯紪璇戝畨瑁呬綅缃?prefix)聽/usr/local/software_name
鑴氭湰浠ュ強缁存姢绋嬪簭瀛樻斁浣嶇疆聽/usr/local/sbin
MySQL聽鏁版嵁搴撲綅缃?data/mysql/data锛堝彲鎸夋儏鍐佃缃級
缃戠珯鏍圭洰褰暵?data/www/wwwroot锛堝彲鎸夋儏鍐佃缃級
铏氭嫙涓繪満鏃ュ織鏍圭洰褰暵?data/logs锛堝彲鎸夋儏鍐佃缃級
Nginx杩愯璐︽埛聽www:www
in_software_name.sh聽瀛樻斁缂栬瘧鍙傛暟鑴氭湰聽涔犳儻灏嗘墍鏈夌紪璇戣剼鏈瓨鏀懼湪in_software_name.sh渚誇簬鍗囩駭鍜屾洿鏂拌蔣浠?
鍒涘緩缃戠珯璐﹀彿鍙婄浉鍏沖瓨鏀劇洰褰
groupadd聽www聽-g聽48
useradd聽-u聽48聽-g聽www聽www
mkdir聽-p聽/data/www/wwwroot
mkdir聽-p聽/data/logs
chmod聽+w聽/data/www/wwwroot
chown聽-R聽www:www聽/data/www/wwwroot
2)聽绯葷粺鐜閮ㄧ講鍙婅皟鏁
妫€鏌ョ郴缁熸槸鍚︽甯
#聽tail聽-n100聽/var/log/messages聽锛堟鏌ユ湁鏃犵郴缁熺駭閿欒淇℃伅锛
#聽dmesg聽锛堟鏌ョ‖浠惰澶囨槸鍚︽湁閿欒淇℃伅锛
#聽ifconfig锛堟鏌ョ綉鍗¤缃槸鍚︽纭級
#聽ping聽www.linuxtone.org聽锛堟鏌ョ綉缁滄槸鍚︽甯革級
3)聽浣跨敤聽yum聽绋嬪簭瀹夎鎵€闇€寮€鍙戝寘锛堜互涓嬩負鏍囧噯鐨劼燫PM聽鍖呭悕绉幫級
娣誨姞鍥藉唴闀滃儚婧愬姞閫熻蔣浠跺畨瑁呬笅杞介€熷害璇峰弬鐓§:http://bbs.linuxtone.org/thread-158-1-1.html
yum聽-y聽install聽ntp聽vim-enhanced聽gcc聽gcc-c++聽gcc-g77聽flex聽bison聽autoconf聽automake聽bzip2-devel聽\
ncurses-devel聽libtool*聽zlib-devel聽libxml2-devel聽libjpeg-devel聽libpng-devel聽libtiff-devel聽\
fontconfig-devel聽freetype-devel聽libXpm-devel聽gettext-devel聽curl聽curl-devel聽pam-devel聽kernel
鍙戝寘瑁呬笂銆
4)聽瀹氭椂鏍℃鏈嶅姟鍣ㄦ椂閽燂紝瀹氭椂涓庝腑鍥藉浗瀹舵巿鏃朵腑蹇冩巿鏃舵湇鍔″櫒鍚屾
#聽crontab聽-e
鍔犲叆涓€琛岋細
15聽3聽*聽*聽*聽/usr/sbin/ntpdate聽210.72.145.44聽>聽/dev/null聽2>&1
5)聽涓嬭澆缂栬瘧鐩稿叧鐨勬簮鐮佸寘.
#vi聽list聽鍦╨ist鏂囦歡閲屽~鍏ヤ互鍚庝笅杞藉湴鍧€鍒楄〃.
http://www.libgd.org/releases/gd-2.0.35.tar.bz2
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz
http://jaist.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.bz2
http://jaist.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.7.tar.gz
http://www.openssl.org/source/openssl-0.9.8h.tar.gz
http://openbsd.md5.com.ar/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
http://sysoev.ru/nginx/nginx-0.6.31.tar.gz
http://mysql.byungsoo.net/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz
http://cn2.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
http://php-fpm.anight.org/downloads/head/php-5.2.6-fpm-0.5.8.diff.gz
http://pecl.php.net/get/memcache-2.2.3.tgz
http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
http://downloads.phpchina.com/zend/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
#vi聽down.sh聽鍒涘緩涓嬭澆鑴氭湰.聽
#!/bin/bash
for聽i聽in聽`cat聽list`
do
wget聽-c聽$i
done聽
#sh聽down.sh聽鎵ц涓嬭澆鑴氭湰鍗沖彲涓嬭澆鐩稿叧杞歡鍖?
婧愮爜缂栬瘧瀹夎鎵€闇€鍖?Source)
1)聽鍗囩駭OpenSSL鍙奜penSSH
tar聽xvf聽openssl-0.9.8h.tar.gz
cd聽openssl-0.9.8h
#vi聽in_openssl.sh
./config聽--prefix=/usr/local/openssl
make
make聽test
make聽install
#聽sh聽in_openssl.sh
#tar聽xvf聽openssh-5.0p1.tar.gz
#cd聽openssh-5.0p1
#聽vi聽in_openssh.sh
./configure聽\
"--prefix=/usr"聽\
"--with-pam"聽\
"--with-zlib"聽\
"--sysconfdir=/etc/ssh"聽\
"--with-ssl-dir=/usr/local/openssl"聽\
"--with-md5-passwords"
make
make聽install
#聽sh聽in_openssh.sh
绂佺敤聽SSH聽V1聽鍗忚:鎵懼埌#Protocol聽2,1鏀逛負锛歅rotocol聽2
绂佺敤鏈嶅姟鍣ㄧGSSAPI鎵懼埌浠ヤ笅涓よ锛屽苟灏嗗畠浠敞閲婏細
GSSAPIAuthentication聽yes
GSSAPICleanupCredentials聽yes
绂佺敤聽DNS聽鍚嶇О瑙f瀽
鎵懼埌锛?UseDNS聽yeas鏀逛負锛歎seDNS聽no
绂佺敤瀹㈡埛绔燝SSAPI
#聽vi聽/etc/ssh/ssh_config聽鎵懼埌锛欸SSAPIAuthentication聽yes聽灏嗚繖琛屾敞閲婃帀銆
鏈€鍚庯紝纭淇敼姝g‘鍚庨噸鏂闆惎鍔燬SH聽鏈嶅姟
#init_ssh.sh
ssh_cf=鈥?etc/ssh/sshd_config鈥
sed聽-i聽-e聽鈥?4聽s/^/#/鈥櫬?i聽-e聽鈥?6聽s/^/#/鈥櫬?ssh_cf
sed聽-i聽鈥渟/#UseDNS聽yes/UseDNS聽no/鈥澛?ssh_cf
#client
sed聽-i聽-e聽鈥?4聽s/^/#/鈥櫬?i聽-e聽鈥?8聽s/^/#/鈥櫬?ssh_cf
echo聽鈥渟sh聽is聽init聽is聽ok鈥︹€︹€︹€?.鈥
#聽service聽sshd聽restart
#聽ssh聽-v聽纭聽OpenSSH聽浠ュ強聽OpenSSL聽鐗堟湰姝g‘銆
浠ヤ笂SSH閰嶇疆鍙埄鐢ㄤ互涓嬭剼鏈嚜鍔ㄤ慨鏀跟
#vi聽init_ssh.sh聽
#init_ssh.sh
ssh_cf="/etc/ssh/sshd_config"
sed聽-i聽-e聽'74聽s/^/#/'聽-i聽-e聽'76聽s/^/#/'聽$ssh_cf
sed聽-i聽"s/#UseDNS聽yes/UseDNS聽no/"聽$ssh_cf
#client
sed聽-i聽-e聽'44聽s/^/#/'聽-i聽-e聽'48聽s/^/#/'聽$ssh_cf
echo聽"ssh聽is聽init聽is聽ok.............."
#sh聽init_ssh.sh
[root@servers聽src]#聽/etc/init.d/sshd聽restart
Stopping聽sshd:聽[聽OK聽]
Starting聽sshd:聽[聽OK聽]
[root@servers聽src]#聽ssh聽-v
OpenSSH_5.0p1,聽OpenSSL聽0.9.8h聽28聽May聽2008
2)聽GD2
#聽cd聽/usr/local/src
#聽tar聽xvf聽gd-2.0.35.tar.gz
#聽cd聽gd-2.0.35
#聽vi聽in_gd2.sh聽
aclocal
./configure聽--prefix=/usr/local/gd2
make聽&&聽make聽install
#聽sh聽in_gd2.sh
3)聽tar聽xvf聽libmcrypt-2.5.8.tar.bz2
cd聽libmcrypt-2.5.8聽
#vi聽in_libmcrypt.sh
./configure聽--prefix=/usr/local/libmcrypt聽&&聽make聽&&聽make聽install
#sh聽in.sh
4)聽#tar聽xvf聽libiconv-1.12.tar.gz
#cd聽libiconv-1.12
#vi聽in_iconv.sh聽
./configure聽--prefix=/usr聽&&聽make聽&&聽make聽install
#sh聽in_iconv.sh
5)聽缂栬瘧瀹夎MySQL
#聽tar聽xvf聽mysql-5.0.51b.tar.gz
#聽cd聽mysql-5.0.51b
#聽vi聽in_mysql.sh
CFLAGS="-O3"聽CXX=gcc聽CXXFLAGS="-O3聽-felide-constructors聽\
-fno-exceptions聽-fno-rtti聽-fomit-frame-pointer聽-ffixed-ebp"
./configure聽\
"--prefix=/usr/local/mysql"聽\
"--localstatedir=/data/mysql/data"聽\
"--with-comment=Source"聽\
"--with-server-suffix=-LinuxTone.Org"聽\
"--with-mysqld-user=mysql"聽\
"--without-debug"聽\
"--with-big-tables"聽\
"--with-charset=gbk"聽\
"--with-collation=gbk_chinese_ci"聽\
"--with-extra-charsets=all"聽\
"--with-pthread"聽\
"--enable-static"聽\
"--enable-thread-safe-client"聽\
"--with-client-ldflags=-all-static"聽\
"--with-mysqld-ldflags=-all-static"聽\
"--enable-assembler"聽\
"--without-isam"聽\
"--without-innodb"聽\
"--without-ndb-debug"
make聽&&聽make聽install
useradd聽mysql聽-d聽/data/mysql聽-s聽/sbin/nologin
/usr/local/mysql/bin/mysql_install_db聽--user=mysql
cd聽/usr/local/mysql
chown聽-R聽root:mysql聽.
chown聽-R聽mysql聽/data/mysql/data
cp聽share/mysql/my-huge.cnf聽/etc/my.cnf
cp聽share/mysql/mysql.server聽/etc/rc.d/init.d/mysqld
chmod聽755聽/etc/rc.d/init.d/mysqld
chkconfig聽--add聽mysqld
/etc/rc.d/init.d/mysqld聽start
cd聽/usr/local/mysql/bin
for聽i聽in聽*;聽do聽ln聽-s聽/usr/local/mysql/bin/$i聽/usr/bin/$i;聽done
#sh聽in_mysql.sh
1.PHP(Fastcgi)缂栬瘧瀹夎聽
1)php-fpm聽缁橮HP(Fastcgi)鎵撹ˉ涓
#tar聽xvf聽php-5.2.6.tar.bz2
#gzip聽-cd聽php-5.2.6-fpm-0.5.8.diff.gz聽|聽patch聽-d聽php-5.2.6聽-p1
2)PHP(Fastcgi)瀹夎.
#cd聽php-5.2.6
#vi聽in_php5.sh
./configure聽\
"--prefix=/usr/local/php-fcgi"聽\
"--enable-fastcgi"聽\
"--enable-fpm"聽\
"--enable-discard-path"聽\
"--enable-force-cgi-redirect"聽\
"--with-config-file-path=/usr/local/php-fcgi/etc"聽\
"--enable-zend-multibyte"聽\
"--with-mysql=/usr/local/mysql"聽\
"--with-libxml-dir"聽\
"--with-iconv-dir=/usr/lib"聽\
"--with-xmlrpc"聽\
"--with-gd=/usr/local/gd2"聽\
"--with-jpeg-dir"聽\
"--with-png-dir"聽\
"--with-bz2"聽\
"--with-freetype-dir"聽\
"--with-zlib-dir聽"聽\
"--with-openssl=/usr/local/openssl"聽\
"--with-mcrypt=/usr/local/libmcrypt"聽\
"--enable-sysvsem"聽\
"--enable-inline-optimization"聽\
"--enable-soap"聽\
"--enable-gd-native-ttf"聽\
"--enable-ftp"聽\
"--enable-mbstring"聽\
"--enable-exif"聽\
"--disable-debug"聽\
"--disable-ipv6"
make聽&&聽make聽install
cp聽php.ini-dist聽/usr/local/php-fcgi/etc/php.ini
#sh聽in_php5.sh
4)瀹夎Xcache
tar聽xvf聽xcache-1.2.2.tar.gz
cd聽xcache-1.2.2
#vi聽in_xcache.sh
/usr/local/php-fcgi/bin/phpize
./configure聽--enable-xcache聽--enable-xcache-coverager聽--with-php-config=/usr/local/php-
fcgi/bin/php-config聽\
--enable-inline-optimization聽--disable-debug
make聽&&聽make聽install
#sh聽in_xcache.sh
#vi聽/usr/local/php-fcgi/etc/php.ini聽#缂栬緫php.ini鍦ㄥ叾鍐呭鏈€鍚庡姞鍏ュ涓嬪唴瀹跟
[xcache-common]
zend_extension聽=聽/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
xcache.admin.user聽=聽鈥渁dmin鈥
;濡備綍鐢熸垚md5瀵嗙爜:聽echo聽-n聽鈥減assword鈥潀聽md5sum
xcache.admin.pass聽=聽鈥?35d849226a8a10be1a5e0fec1f0f3ce鈥澛?瀵嗙爜涓?2netseek
[xcache]
;聽Change聽xcache.size聽to聽tune聽the聽size聽of聽the聽opcode聽cache
xcache.size聽=聽24M
xcache.shm_scheme聽=聽鈥渕map鈥
xcache.count聽=聽4
xcache.slots聽=聽8K
xcache.ttl聽=聽0
xcache.gc_interval聽=聽0
;聽Change聽xcache.var_size聽to聽adjust聽the聽size聽of聽variable聽cache
xcache.var_size聽=聽8M
xcache.var_count聽=聽1
xcache.var_slots聽=聽8K
xcache.var_ttl聽=聽0
xcache.var_maxttl聽=聽0
xcache.var_gc_interval聽=聽300
xcache.test聽=聽Off
xcache.readonly_protection聽=聽On
xcache.mmap_path聽=聽鈥?dev/zero鈥
xcache.coredump_directory聽=聽鈥溾€
xcache.cacher聽=聽On
xcache.stat聽=聽On
xcache.optimizer聽=聽Off
[xcache.coverager]
xcache.coverager聽=聽On
xcache.coveragedump_directory聽=聽鈥溾€
4)瀹夎Memcache
cd聽memcache-2.2.3
#vi聽in_memcache.sh
/usr/local/php-fcgi/bin/phpize
./configure聽--with-php-config=/usr/local/php-fcgi/bin/php-config
make聽&&聽make聽install
#sh聽in_memcache.sh
5)聽PHP鍒濆鍖栬剼鏈
#聽cat聽init_fcgi.sh
#!/bin/bash
#php-fastcgi.php
fcgi_cf="/usr/local/php-fcgi/etc/php.ini"
sed聽-i聽'205聽s#;open_basedir聽=#open_basedir聽=聽/data/www/wwwroot:/tmp#g'聽$fcgi_cf
sed聽-i聽'210聽s#disable_functions聽=#disable_functions聽=聽
phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_
alter,ini_alter,ini_restore,
dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g'聽$fcgi_cf
sed聽-i聽'/expose_php/s/On/Off/'聽$fcgi_cf
sed聽-i聽'/display_errors/s/On/Off/'聽$fcgi_cf
sed聽-i聽's#extension_dir聽=聽"./"#extension_dir聽=聽"/usr/local/php-fcgi/lib/php/extensions/no-debug-
non-zts-20060613/"\nextension聽
=聽"memcache.so"\n#'聽$fcgi_cf
6)ZendOptimizer-3.3.3-linux-glibc23-i386聽(瑙e帇鍚庤繘鍏ョ洰褰?/install锛屽畨鎻愮ず閫夋嫨鐩稿叧鐨勭洰褰曞強
閰嶇疆鏂囦歡瀛樻斁鐩綍鍗沖彲)
1)Nginx缂栬瘧瀹夎
cd聽nginx-0.6.31
#vi聽in_nginx.sh
./configure聽--user=www聽--group=www聽--prefix=/usr/local/nginx/聽--with-http_stub_status_module聽--
with-
openssl=/usr/local/openssl
sh聽in_nginx.sh
2)鍒濆鍖朜ginx鐩稿叧閰嶇疆
#mkdir聽/usr/local/nginx/conf/vhosts聽鍒涘緩瀛樻斁铏氭嫙涓繪満閰嶇疆鏂囦歡鐩綍
#cd聽/usr/local/nginx/conf
#mv聽nginx.conf聽nginx.conf_back聽灏嗗師閰嶇疆鏂囦歡澶囦喚渚涗互鍚庡弬鑰?
#vi聽nginx.conf聽閲嶆柊鍒涘緩nginx涓婚厤缃枃浠
user聽www聽www;
worker_processes聽8;
pid聽/var/run/nginx.pid;
#聽[聽debug聽|聽info聽|聽notice聽|聽warn聽|聽error聽|聽crit聽]
#error_log聽/var/log/nginx.error_log聽info;
#Specifies聽the聽value聽for聽maximum聽file聽descriptors聽that聽can聽be聽opened聽by聽this聽process.
worker_rlimit_nofile聽51200;
events
{
use聽epoll;
#maxclient聽=聽worker_processes聽*聽worker_connections聽/聽cpu_number
worker_connections聽51200;
}
http
include聽mime.types;
default_type聽application/octet-stream;
charset聽gb2312;
server_names_hash_bucket_size聽128;
log_format聽main聽鈥?remote_addr聽-聽$remote_user聽[$time_local]聽$request聽鈥
鈥樷€?status鈥澛?body_bytes_sent聽鈥?http_referer鈥澛犫€
鈥樷€?http_user_agent鈥澛犫€?http_x_forwarded_for鈥濃€楙
#access_log聽/data/www/logs/access.log聽main;
access_log聽/dev/null;
sendfile聽on;
tcp_nopush聽on;
keepalive_timeout聽60;
tcp_nodelay聽on;
fastcgi_connect_timeout聽60;
fastcgi_send_timeout聽180;
fastcgi_read_timeout聽180;
fastcgi_buffer_size聽128k;
fastcgi_buffers聽4聽128k;
fastcgi_busy_buffers_size聽128k;
fastcgi_temp_file_write_size聽128k;
fastcgi_intercept_errors聽on;
gzip聽on;
gzip_min_length聽1k;
gzip_buffers聽4聽8k;
gzip_http_version聽1.1;
gzip_types聽text/plain聽application/x-javascript聽text/css聽text/html聽application/xml;
#
client_max_body_size聽10m;
client_body_buffer_size聽256k;
#proxy_temp_path聽/dev/shm/proxy_temp;
fastcgi_temp_path聽/dev/shm/fastcgi_temp;
client_body_temp_path聽/dev/shm/client_body_temp;
#聽The聽following聽includes聽are聽specified聽for聽virtual聽hosts
include聽vhosts/bbs.linxutone.org.conf;
include聽vhosts/down.redocn.com.conf;
include聽vhosts/count.linuxtone.org.conf;
fastcgi_pass聽127.0.0.1:8085;
fastcgi_index聽index.php;
fastcgi_param聽GATEWAY_INTERFACE聽CGI/1.1;
fastcgi_param聽SERVER_SOFTWARE聽nginx;
fastcgi_param聽QUERY_STRING聽$query_string;
fastcgi_param聽REQUEST_METHOD聽$request_method;
fastcgi_param聽CONTENT_TYPE聽$content_type;
fastcgi_param聽CONTENT_LENGTH聽$content_length;
fastcgi_param聽SCRIPT_FILENAME聽$document_root$fastcgi_script_name;
fastcgi_param聽SCRIPT_NAME聽$fastcgi_script_name;
fastcgi_param聽REQUEST_URI聽$request_uri;
fastcgi_param聽DOCUMENT_URI聽$document_uri;
fastcgi_param聽DOCUMENT_ROOT聽$document_root;
fastcgi_param聽SERVER_PROTOCOL聽$server_protocol;
fastcgi_param聽REMOTE_ADDR聽$remote_addr;
fastcgi_param聽REMOTE_PORT聽$remote_port;
fastcgi_param聽SERVER_ADDR聽$server_addr;
fastcgi_param聽SERVER_PORT聽$server_port;
fastcgi_param聽SERVER_NAME聽$server_name;
#聽PHP聽only,聽required聽if聽PHP聽was聽built聽with聽--enable-force-cgi-redirect
#fastcgi_param聽REDIRECT_STATUS聽200;
#vi聽/enable_php5.conf聽Nginx鏀寔PHP閰嶇疆鏂囦歡.
聽
3)閰嶇疆淇敼php-fpm鑴氭湰
閰嶇疆php-fpm鑴氭湰:
cd聽/usr/local/php-fcgi/etc/
vi聽php-fpm.conf聽淇敼濡備笅鍐呭:(杩涘叆vi缂栬緫鍣紝杈撳叆:set聽nu聽鏄劇ず琛屽彿.)
[code]
41聽127.0.0.1:8085
62聽Unix聽user聽of聽processes
63聽www
65聽Unix聽group聽of聽processes
66聽www
79聽128
80
81聽Settings聽group聽for聽鈥榓pache-like鈥櫬爌m聽style
82聽
83
84聽Sets聽the聽number聽of聽server聽processes聽created聽on聽
startup.
85聽Used聽only聽when聽鈥榓pache-like鈥櫬爌m_style聽is聽selected
86聽20
87
88聽Sets聽the聽desired聽minimum聽number聽of聽idle聽server聽
processes.
89聽Used聽only聽when聽鈥榓pache-like鈥櫬爌m_style聽is聽selected
90聽5
91
92聽Sets聽the聽desired聽maximum聽number聽of聽idle聽server聽
93聽Used聽only聽when聽鈥榓pache-like鈥櫬爌m_style聽is聽selected
94聽250
104聽Set聽open聽file聽desc聽rlimit
105聽51200
106
107聽Set聽max聽core聽size聽rlimit
108聽0
109
110聽Chroot聽to聽this聽directory聽at聽the聽start
111聽
112
113聽Chdir聽to聽this聽directory聽at聽the聽start
114聽
115
116聽Redirect聽workers鈥櫬爏tdout聽and聽stderr聽into聽main聽error聽log.
117聽If聽not聽set,聽they聽will聽be聽redirected聽to聽/dev/null,聽according聽to聽
FastCGI聽specs
118聽yes
119
120聽How聽much聽requests聽each聽process聽should聽execute聽before聽respawn.
121聽Useful聽to聽work聽around聽memory聽leaks聽in聽3rd聽party聽libraries.
122聽For聽endless聽request聽processing聽please聽specify聽0
123聽Equivalent聽to聽PHP_FCGI_MAX_REQUESTS
124聽51200
4)聽Nginx+PHP(fastcgi)鍚姩鑴氭湰鍙傝€傶http://bbs.linuxtone.org/thread-372-1-2.html
#vi聽/usr/local/nginx/conf/vhosts/bbs.linuxtone.org.conf
server
{
listen聽80;
server_name聽bbs.linuxtone.org聽www.linuxtone.org;
index聽index.html聽index.php聽index.htm;
root聽/data/www/wwwroot/lt/bbs;
#access_log聽/var/log/nginx/access_bbs.redocn.com.log聽combined;
location聽/聽{
if聽(!-e聽$request_filename)聽{
rewrite聽^/archiver/((fid|tid)-[\w\-]+\.html)$聽/archiver/index.php?$1聽
last;
rewrite聽^/forum-([0-9]+)-([0-9]+)\.html$聽/forumdisplay.php?
fid=$1&page=$2聽last;
rewrite聽^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$聽/viewthread.php?
tid=$1&extra=page%3D$3&page=$2聽
rewrite聽^/space-(username|uid)-(.+)\.html$聽/space.php?$1=$2聽last;
rewrite聽^/tag-(.+)\.html$聽/tag.php?name=$1聽last;
break;
#Preventing聽hot聽linking聽of聽p_w_picpaths聽and聽other聽file聽types
location聽~*聽^.+\.(gif|jpg|png|swf|flv|rar|zip)$聽{
valid_referers聽none聽blocked聽server_names聽*.linuxtone.org聽http://localhost;
if聽($invalid_referer)聽{
rewrite聽^/聽http://bbs.linuxtone.org/p_w_picpaths/default/logo.gif;
return聽403;
#聽Add聽expires聽header聽for聽static聽content
location聽~*聽\.(js|css|jpg|jpeg|gif|png|swf)$聽{
if聽(-f聽$request_filename)聽{
root聽/data/www/wwwroot/lt/bbs;
expires聽1d;
#support聽php
location聽~聽.*\.php?$
include聽enable_php5.conf;
vi聽/usr/local/nginx/conf/vhosts/down.redocn.com.conf
limit_zone聽one聽$binary_remote_addr聽10m;
server
{
listen聽80;
server_name聽down.redocn.com;
index聽index.html聽index.htm聽index.php;
root聽/data/www/wwwroot/down;
error_page聽404聽/index.php;
#聽redirect聽server聽error聽pages聽to聽the聽static聽page聽/50x.html
error_page聽500聽502聽503聽504聽/50x.html;
location聽=聽/50x.html聽{
root聽html;
}
#Zone聽limit
location聽/聽{
limit_conn聽one聽1;
limit_rate聽20k;
}
#聽serve聽static聽files
location聽~聽^/(p_w_picpaths|javascript|js|css|flash|media|static)/聽{
root聽/data/www/wwwroot/down;
expires聽30d;
瀹炵幇杈撳叆http://count.linuxtone.org/tongji聽瑕佹眰杈撳叆鐢ㄦ埛鍚嶅拰瀵嗙爜楠岃瘉鎵嶅彲鏌ョ湅鍐呭唴銆傞厤缃柟
娉曞涓嬶細
鍒涘緩缁熻閰嶇疆鏂囦歡:
mkdir聽/usr/local/nginx/conf/htpasswd聽#鍒涘緩瀛樻斁瀵嗙爜鐨勭洰褰
/usr/local/apache2/bin/htpasswd聽-c聽/usr/local/nginx/conf/htpasswd/tongji聽admin
server
listen聽80;
server_name聽count.linuxtone.org聽211.100.72.138;
index聽index.html聽index.php;
root聽/data/www/wwwroot/count;
access_log聽/data/logs/access_count.linuxtone.org.log聽combined;
#error聽page
error_page聽404聽http://www.linuxtone.org/error.html;
error_page聽500聽502聽503聽504聽http://www.linuxtone.org;
#expires聽static聽files
location聽~*聽\.(js|css|jpg|jpeg|gif|png)$聽{
access_log聽off;
location聽~聽^/(tongji)/聽{
auth_basic聽"LT-COUNT-TongJi";
auth_basic_user_file聽/usr/local/nginx/conf/htpasswd/tongji;
鍦ㄧ浉鍏寵櫄鎷熶富鏈洪厤缃枃浠跺姞鍏ュ涓嬭缃嵆鍙紝鏇村璇峰弬鑰冨畼鏂箇iki
location聽/聽{
autoindex聽on;
}
cd聽nginx-0.6.31/src/core
#define聽NGINX_VERSION聽"1.2"
#define聽NGINX_VER聽"LTWS/"聽NGINX_VERSION
浠嶅悗閲嶆柊缂栬瘧nginx鍗沖彲锛屾煡鐪嬩竴涓嬫晥鏋淂
[root@count聽~]#聽curl聽-I聽http://bbs.linuxtone.org
HTTP/1.1聽200聽OK
Server:聽LTWS/1.2
Date:聽Mon,聽23聽Jun聽2008聽06:11:17聽GMT
Content-Type:聽text/html;聽charset=gb2312
Transfer-Encoding:聽chunked
Connection:聽keep-alive
Set-Cookie:聽lt__sid=cJN2FT;聽expires=Mon,聽30-Jun-2008聽06:11:17聽GMT;聽path=/
Set-Cookie:聽lt__onlineusernum=228;聽expires=Mon,聽23-Jun-2008聽06:16:17聽GMT;聽path=/
6.鍑忓皬nginx缂栬瘧鍚庣殑鏂囦歡澶у皬聽(Reduce聽file聽size聽of聽nginx)
榛樿鐨刵ginx缂栬瘧閫夐」閲屽眳鐒舵槸鐢╠ebug妯″紡(-g)鐨勶紙debug妯″紡浼氭彃鍏ュ緢澶氳窡韪拰ASSERT涔嬬被锛夛紝缂栬瘧浠ュ悗涓€涓
nginx鏈夊ソ鍑犲厗銆
鍘繪帀nginx鐨刣ebug妯″紡缂栬瘧锛岀紪璇戜互鍚庡彧鏈?80K(nginx-0.6.31聽,聽gcc4)銆
[root@ssatt聽local]#聽du聽-sh聽nginx
480K聽nginx
鍦╝uto/cc/gcc锛屾渶鍚庡嚑琛屾湁锛
#聽debug
CFLAGS="$CFLAGS聽-g"
娉ㄩ噴鎺夋垨鍒犳帀杩欏嚑琛岋紝閲嶆柊缂栬瘧鍗沖彲
[root@count聽~]#聽crontab聽-l
59聽23聽*聽*聽*聽/usr/local/sbin/logcron.sh聽/dev/null聽2>&1