




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、利用Nginx替彳apache實(shí)現(xiàn)高性能的Web環(huán)境利用Nginx替彳apache實(shí)現(xiàn)高性能的Web環(huán)境Nginx介紹:Nginx發(fā)音為enginex,是由俄羅斯人IgorSysoev建立的項(xiàng)目,基于BSD許可。據(jù)說他當(dāng)初是F5的成員之一,英文主頁(yè):。俄羅斯的一些大網(wǎng)站已經(jīng)使用它超過兩年多了,一直表現(xiàn)不凡,相信想了解nginx的朋友都讀過阿葉大哥的利用nginx實(shí)現(xiàn)負(fù)載均衡的文章相關(guān)鏈接見(六)。測(cè)試環(huán)境:紅動(dòng)中國(guó)(redocn)提供運(yùn)營(yíng)服務(wù)器環(huán)境.關(guān)于紅動(dòng)服務(wù)環(huán)境:紅動(dòng)中國(guó)在早期利用apache環(huán)境,再加上一些優(yōu)化的工作,一直是相對(duì)很穩(wěn)定,但是最近由于網(wǎng)站發(fā)展,訪問量越來越大,在線人數(shù)一多經(jīng)
2、常出現(xiàn),負(fù)載過高,性能急劇下降,經(jīng)過雙木站長(zhǎng)的同意,考慮是否能利用nginx來代替apache,經(jīng)過長(zhǎng)時(shí)間的觀察目前nginx工作很穩(wěn)定,系統(tǒng)也不會(huì)再說現(xiàn)高負(fù)載的狀況,占用內(nèi)存也很低,訪問速率從用戶體驗(yàn)來看明顯有提升.關(guān)于紅動(dòng)中國(guó):紅動(dòng)中國(guó)(redocn)論壇經(jīng)過近1年的快速發(fā)展,目前日均頁(yè)面訪問量超過100萬(wàn),位居全球設(shè)計(jì)論壇(中文)第1位,是國(guó)內(nèi)最具影響力的設(shè)計(jì)論壇之一。目前論壇擁有近20萬(wàn)會(huì)員,包括眾多設(shè)計(jì)界領(lǐng)軍人物在內(nèi)的行業(yè)中堅(jiān)力量、相關(guān)藝術(shù)院校師生以及部分設(shè)計(jì)愛好者等。遷移目標(biāo):實(shí)現(xiàn)網(wǎng)站論壇靜態(tài)化,防盜鏈,下載并發(fā)數(shù)和速率限制,實(shí)現(xiàn)原站apache所具有的所有功能,將原apache環(huán)
3、境下的站點(diǎn)全部遷移到Nginx一.PHP(Fastcgi)編譯安裝rootattphp-5.2.4#catin.sh./configure-prefix=/usr/local/php-fcgi-enable-fastcgi-enable-discard-path-enable-force-cgi-redirectjwith-config-file-path=/usr/local/php-fcgi/etc-enable-zend-multibytewith-mysql=/usr/local/mysqlwith-libxml-dir=/usr/local/libxml2with-gd=/usr/l
4、ocal/gd2mith-jpeg-dirmith-png-dirmith-bz2with-freetype-dirmith-iconv-dirmith-zlib-dirmith-openssH/usr/local/opensslwith-mcrypt=/usr/local/libmcrypt-enable-sysvsem-enable-inline-optimization-enable-soap-enable-gd-native-ttA-enable-ftp-enable-mbstringenable-exif-disable-debug-disable-ipv6makemakeinsta
5、llcpphp.ini-dist/usr/local/php-fcgi/etc/php.ini復(fù)制代碼注:關(guān)于如何安裝gd庫(kù),mysql的編譯安裝,本文將不介紹,本文重點(diǎn)在于介紹nginx的安裝與配置,如想了解其它相關(guān)的問題可以到LinuxPk去找相關(guān)的貼子( HYPERLINK )二.Nginx編譯安裝1.創(chuàng)建nginx運(yùn)行用戶和虛擬主機(jī)目錄groupaddwww-g48useradd-u48-gwwwwwwmkdir-p/data/www/wwwrootchown-Rwww:www/data/www/wwwroot復(fù)制代碼2.安裝lighttpd中附帶的spawn-fcgi,用來啟動(dòng)php
6、-cgi先編譯安裝lighttpd產(chǎn)生spawn-fcgi二進(jìn)制文件.cd/usr/local/src/lighttpd-1.4.18 HYPERLINK / /cpsrc/spawn-fcgi/usr/local/php-fcgi/bin/復(fù)制代碼啟動(dòng)php-cgi進(jìn)程,監(jiān)聽的8085端口,進(jìn)程數(shù)為250(如果服務(wù)器內(nèi)存小于可以只開啟25個(gè)進(jìn)程),用戶為www:/usr/local/php-fcgi/bin/spawn-fcgi-a-p8085-C250-uwww-f/usr/local/php-fcgi/bin/php-cgi3.nginx的安裝與配置安裝Nginx所需的pcre庫(kù): HY
7、PERLINK /exim/pcre/pcre-7.3.tar.gz /exim/pcre/pcre-7.3.tar.gztarzxvfpcre-7.2.tar.gzcdpcre-7.2/./configuremake&makeinstallcd./ HYPERLINK http:/sysoev.ru/nginx/nginx-0.5.32.tar.gz http:/sysoev.ru/nginx/nginx-0.5.32.tar.gztarzxvfnginx-0.5.32.tar.gzcdnginx-0.5.32./configureuser=www-group=www-prefix=/usr
8、/local/nginx/with-http_stub_status_moduleth-openssl=/usr/local/opensslmake&makeinstall復(fù)制代碼此模塊非核心模塊,需要在編譯的時(shí)候手動(dòng)添加編譯參數(shù)-with-http_stub_status_moduleI,:fIlli配置nginx三.Nginx主配置文件及PHP支持.1.nginx.conf主配置文件的配置#cd/usr/local/nginx/conf/#cpnginx.confnginx.conf.cao#cat/dev/nullnginx.conf3GB ,wi#vinginx.conf/主配置文件u
9、serwwwwww;worker_processes10;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;pid/var/run/nginx.pid;#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.worker_rlimit_nofile51200;eventsuseepoll;#maxclient=worker_processes*worker_connections/cpu_
10、numberworker_connections51200;httpincludeconf/mime.types;default_typeapplication/octet-stream;log_formatmain$remote_add-r$remote_user$time_local$request$status$body_bytes_sent$http_referer$http_user_agent$http_x_forwarded_for;#access_log/data/www/logs/access.logmain;#sendfileon;tcp_nopushon;tcp_node
11、layoff;keepalive_timeout60;client_header_timeout3m;client_body_timeout3m;send_timeout3m;connection_pool_size256;client_header_buffer_size1k;large_client_header_buffers42k;request_pool_size4k;output_buffers432k;postpone_output1460;client_max_body_size10m;client_body_buffer_size256k;client_body_temp_p
12、ath/dev/shm/client_body_temp;proxy_temp_path/usr/local/nginx/proxy_temp;fastcgi_temp_path/usr/local/nginx/fastcgi_temp;#gzipgzipon;gzip_http_version1.0;gzip_comp_level2;gzip_proxiedany;gzip_typestext/plaintext/htmltext/cssapplication/x-javascripttext/xmlapplication/xmlapplication/xmlrsstext/javascri
13、pt;gzip_min_length1100;gzip_buffers48k;#Thefollowingincludesarespecifiedforvirtualhosts/以下是加載虛擬主機(jī)配置.# HYPERLINK includeconf/vhosts/www_redocn_com.conf;#includeconf/vhosts/bbs_redocn_com.conf;#includeconf/vhosts/blog_redocn_com.conf;#includeconf/vhosts/down_redocn_com.conf;復(fù)制代碼2.配置支持Fastcgi模式的PHProot
14、redocnconf#catenable_php5.conffastcgi_pass:8085;fastcgi_indexindex.php;fastcgi_paramGATEWAY_INTERFACECGI/1.1;fastcgi_paramSERVER_SOFTWAREnginx;#newacupload#fastcgi_pass_request_bodyoff;#client_body_in_file_onlyclean;#fastcgi_paramREQUEST_BODY_FILE$request_body_file;#fastcgi_paramQUERY_STRING$query_s
15、tring;fastcgi_paramREQUEST_METHOD$request_method;fastcgi_paramCONTENT_TYPE$content_type;fastcgi_paramCONTENT_LENGTH$content_length;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramSCRIPT_NAME$fastcgi_script_name;fastcgi_paramREQUEST_URI$request_uri;fastcgi_paramDOCUMENT_UR
16、I$document_uri;fastcgi_paramDOCUMENT_ROOT$document_root;fastcgi_paramSERVER_PROTOCOL$server_protocol;fastcgi_paramREMOTE_ADDR$remote_addr;fastcgi_paramREMOTE_PORT$remote_port;fastcgi_paramSERVER_ADDR$server_addr;fastcgi_paramSERVER_PORT$server_port;fastcgi_paramSERVER_NAME$server_name;#PHPonly,requi
17、redifPHPwasbuiltwith-enable-force-cgi-redirectfastcgi_paramREDIRECT_STATUS200;復(fù)制代碼四,多虛擬主機(jī)應(yīng)用配置案例.#mkdir/usr/local/nginx/conf/vhosts/建立虛擬主機(jī)配置存放目錄1./首站配置rootredocnvhosts#viwww_redocn_com.confserverlisten80;server_;indexindex.htmlindex.htmindex.php;root/data/www/wwwroot;error_page404 HYPERLINK ;rewriteA
18、/bbs/(.*) HYPERLINK / /$1;location.*.php?$includeconf/enable_php5.conf;復(fù)制代碼注:關(guān)于rewite需求,紅動(dòng)中國(guó)希望當(dāng)用戶訪問 HYPERLINK /bbs /bbs的時(shí)候自動(dòng)轉(zhuǎn)至 HYPERLINK 在原apache中利用redirect實(shí)現(xiàn)Redirect/bbs HYPERLINK 本文中在nginx下利用rewrite實(shí)現(xiàn):rewriteA/bbs/(.*) HYPERLINK / /$1;2.rootredocnvhostsvibbs_redocn_com.confserverlisten80;server_;i
19、ndexindex.htmlindex.htmindex.php;root/home/www/htdocs/bbs;access_log/var/log/nginx/access_.logcombined;location/#bbsrewriterewriteA/archiver/(fid|tid)-w-.html)$/archiver/index.php?$1last;rewriteA/forum-(0-9)-(0-9).html$/forumdisplay.php?fid=$1&page=$2last;rewriteA/thread-(0-9)-(0-9)-(0-9).html$/view
20、thread.php?tid=$1&extra=page=$3&page=$2last;rewriteA/space-(username|uid)-(.).html$/space.php?$1=$2last;rewriteA/tag-(.).html$/tag.php?name=$1last;break;#errorerror_page404/index.php;#redirectservererrorpagestothestaticpage/50 x.htmlerror_page500502503504/50 x.html;location=/50 x.htmlroothtml;#Preve
21、ntinghotlinkingofimagesandotherfiletypeslocation*A.(gif|jpg|png|swf|flv|rar|zip)$valid_referersnoneblockedserver_names*.*.*.*.*.*.*.cn*.;if($invalid_referer)rewrite/ HYPERLINK /images/redocn.gif /images/redocn.gif;#return403;#supportphplocation.*.php?$includeconf/enable_php5.conf;復(fù)制代碼注:紅動(dòng)中國(guó)采用高性能的Dis
22、cuz!論壇,原apache的rewrite規(guī)則幾乎不要做什么修改即可全部移植到nginx下.靜態(tài)化配置見面上面的:#bbsrewrite部分.一般論壇都希望實(shí)現(xiàn)防盜鏈功能,在apache很輕松實(shí)現(xiàn)?在nginx下是否容易實(shí)現(xiàn)呢?答案是肯定的.#Preventinghotlinkingofimagesandotherfiletypesvalid_referersnoneblockedserver_names*.你允許連接的網(wǎng)址if($invalid_referer)rewrite/ HYPERLINK /images/redocn.gif /images/redocn.gif;/讓另II人盜鏈
23、時(shí)顯示你指定的圖片.#return403;復(fù)制代碼3.rootredocnvhosts#viblog_redocn_com.confserverlisten80;server_;indexindex.htmlindex.htmindex.php;root/data/www/wwwroot/blog;error_page404 HYPERLINK ;#supsiterewriterewriteA(0-9)/spacelist(.*)$index.php?$1/action_spacelist$2;rewriteA(0-9)/viewspace_(.)$index.php?$1/action_vi
24、ewspace_itemid_$2;rewriteA(0-9)/viewbbs_(.)$index.php?$1/action_viewbbs_tid_$2;rewriteA(0-9)/(.*)$index.php?$1/$2;rewriteA(0-9)$index.php?$1;rewriteAaction_(.)$index.php?action_$1;rewriteAcategory_(.)$index.php?action_category_catid_$1;rewriteAitemlist_(.)$index.php?action_itemlist_catid_$1;rewriteA
25、viewnews_(.)$index.php?action_viewnews_itemid_$1;rewriteAviewthread_(.)$index.php?action_viewthread_tid_$1;rewriteAindex(.a-zA-Z0-9*)$index.php;rewriteAhtml/(0-9)/viewnews_itemid_(0-9).html$index.php?action_viewnews_itemid_$2;rewriteA/(0-9)/spacelist(.)$/index.php?uid/$1/action/spacelist/type$2;rewr
26、iteA/(0-9)/viewspace(.)$/index.php?uid/$1/action/viewspace/itemid$2;rewriteA/(0-9)/viewbbs(.)$/index.php?uid/$1/action/viewbbs/tid$2;rewriteA/(0-9)/(.*)$/index.php?uid/$1/$2;rewriteA/(0-9)$/index.php?uid/$1;rewriteA/action(.)$/index.php?action$1;rewriteA/category(.)$/index.php?action/category/catid$
27、1;rewriteA/viewnews(.)$/index.php?action/viewnews/itemid$1;rewriteA/viewthread(.)$/index.php?action/viewthread/tid$1;rewriteA/mygroup(.)$/index.php?action/mygroup/gid$1;location.*.php?$includeconf/enable_php5.conf;復(fù)制代碼注:blog采用功能強(qiáng)大的Supesite作為Blog站點(diǎn):/1.Blog如何在Nginx里實(shí)現(xiàn)靜態(tài)化,具體設(shè)置見,上面的#supesiterewrite.root
28、redocnvhosts#vidown_redocn_com.conflimit_zoneone$binary_remote_addr10m;serverlisten80;server_;indexindex.htmlindex.htmindex.php;root/data/www/wwwroot/down;error_page404/index.php;#redirectservererrorpagestothestaticpage/50 x.htmlerror_page500502503504/50 x.html;location=/50 x.htmlroothtml;#Zonelimitlocation/limit_connone1;limit_rate20k;#servestaticfileslocationA/(images|javascript|js|css|flash|media|stat
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- DB14-T 1641-2025 設(shè)施黃瓜病蟲害綠色防控技術(shù)規(guī)程
- 中醫(yī)離奇病案分析
- 2025年熔化焊接與熱切割作業(yè)模擬考試100題及答案
- 銀行財(cái)務(wù)擔(dān)保業(yè)務(wù)合同賬務(wù)操作細(xì)則
- 人工智能產(chǎn)業(yè)園區(qū)廠房土地使用權(quán)抵押擔(dān)保投資合同
- 高效節(jié)水型茶園承包經(jīng)營(yíng)合同樣本
- Brand KPIs for neobanking PagBank in Brazil-英文培訓(xùn)課件2025.4
- Brand KPIs for neobanking Tandem in the United Kingdom-英文培訓(xùn)課件2025.4
- 2025年國(guó)際法專業(yè)考試題及答案參考
- 2025年高校教師教學(xué)能力考試試卷及答案
- 2024年汽車駕駛員(技師)職業(yè)鑒定理論考試題庫(kù)(含答案)
- 上海市市轄區(qū)(2024年-2025年小學(xué)四年級(jí)語(yǔ)文)統(tǒng)編版期末考試(下學(xué)期)試卷及答案
- 叔侄關(guān)系斷絕協(xié)議書
- 中小學(xué)-預(yù)防性騷擾與性侵害-1-課件
- 國(guó)際經(jīng)濟(jì)合作(-第二版)思考題和知識(shí)點(diǎn)運(yùn)用習(xí)題答案
- 江蘇省常州市溧陽(yáng)市2023-2024學(xué)年八年級(jí)下學(xué)期期末道德與法治試題(含答案解析)
- 2024年江蘇省南通市如皋市中考一模語(yǔ)文試題
- SY-T 5374.2-2023 固井作業(yè)規(guī)程 第2部分-特殊固井
- 08J933-1體育場(chǎng)地與設(shè)施(一)
- 分部工程驗(yàn)收流程
- 住建部勞務(wù)分包合同(2024版)
評(píng)論
0/150
提交評(píng)論