




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、.:.;利用Nginx替代apache實現(xiàn)高性能的Web環(huán)境利用Nginx替代apache實現(xiàn)高性能的Web環(huán)境Nginx引見:Nginx發(fā)音為engine x,是由俄羅斯人Igor Sysoev建立的工程,基于BSD答應。聽說他當初是F5的成員之一,英文主頁: HYPERLINK t _blank 。俄羅斯的一些大網(wǎng)站曾經(jīng)運用它超越兩年多了, 不斷表現(xiàn)非凡,置信想了解nginx的朋友都讀過阿葉大哥的利用nginx實現(xiàn)負載平衡的文章相關鏈接見(六)。測試環(huán)境:紅動中國(redocn)提供運營效力器環(huán)境.關于紅動效力環(huán)境:紅動中國在早期利用apache環(huán)境,再加上一些優(yōu)化的任務,不斷是相對很穩(wěn)定
2、,但是最近由于網(wǎng)站開展,訪問量越來越大,在線人數(shù)一多經(jīng)常出現(xiàn),負載過高,性能急劇下降,經(jīng)過雙木站長的贊同,思索能否能利用nginx來替代apache,經(jīng)過長時間的察看目前nginx任務很穩(wěn)定,系統(tǒng)也不會再說現(xiàn)高負載的情況,占用內存也很低,訪問速率從用戶體驗來看明顯有提升.關于紅動中國:紅動中國redocn)論壇經(jīng)過近1年的快速開展,目前日均頁面訪問量超越100萬,位居全球設計論壇(中文)第1位,是國內最具影響力的設計論壇之一。目前論壇擁有近20萬會員,包括眾多設計界領軍人物在內的行業(yè)中堅力量、相關藝術院校師生以及部分設計喜好者等。遷移目的:實現(xiàn)網(wǎng)站論壇靜態(tài)化,防盜鏈,下載并發(fā)數(shù)和速率限制,實現(xiàn)
3、原站apache所具有的一切功能,將原apache環(huán)境下的站點全部遷移到Nginx一.PHP(Fastcgi)編譯安裝rootatt php-5.2.4# cat in.sh./configure prefix=/usr/local/php-fcgi enable-fastcgi 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=/
4、usr/local/libxml2 with-gd=/usr/local/gd2 with-jpeg-dir with-png-dir with-bz2 with-freetype-dir with-iconv-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-ex
5、if disable-debug disable-ipv6makemake installcp php.ini-dist /usr/local/php-fcgi/etc/php.ini復制代碼注:關于如何安裝gd庫,mysql的編譯安裝,本文將不引見,本文重點在于引見nginx的安裝與配置,如想了解其它相關的問題可以到LinuxPk去找相關的貼子( HYPERLINK bbs.linuxpk t _blank bbs.linuxpk)二.Nginx編譯安裝1.創(chuàng)建nginx運轉用戶和虛擬主機目錄groupadd www -g 48useradd -u 48 -g www wwwmkdir -p
6、 /data/www/wwwrootchown -R www:www /data/www/wwwroot復制代碼2.安裝lighttpd中附帶的spawn-fcgi,用來啟動php-cgi先編譯安裝lighttpd產生spawn-fcgi二進制文件.cd /usr/local/src/lighttpd-1.4.18 HYPERLINK knowsky/ t _blank knowsky/cp src/spawn-fcgi /usr/local/php-fcgi/bin/復制代碼啟動php-cgi進程,監(jiān)聽的8085端口,進程數(shù)為250假設效力器內存小于3GB,可以只開啟25個進程,用戶為www
7、:/usr/local/php-fcgi/bin/spawn-fcgi -a -p 8085 -C 250 -u www -f /usr/local/php-fcgi/bin/php-cgi3.nginx的安裝與配置安裝Nginx所需的pcre庫: HYPERLINK /exim/pcre/pcre-7.3.tar.gz t _blank /exim/pcre/pcre-7.3.tar.gz tar zxvf pcre-7.2.tar.gzcd pcre-7.2/./configuremake & make installcd ./ HYPERLINK sysoev.ru/nginx/ngin
8、x-0.5.32.tar.gz t _blank sysoev.ru/nginx/nginx-0.5.32.tar.gztar zxvf nginx-0.5.32.tar.gzcd nginx-0.5.32./configure user=www group=www prefix=/usr/local/nginx/ with-http_stub_status_module with-openssl=/usr/local/opensslmake & make install復制代碼此模塊非中心模塊,需求在編譯的時候手動添加編譯參數(shù) with-http_stub_status_module配置ng
9、inx三.Nginx主配置文件及PHP支持.1.nginx.conf 主配置文件的配置#cd /usr/local/nginx/conf/#cp nginx.conf nginx.conf.cao#cat /dev/null nginx.conf#vi nginx.conf /主配置文件user www www;worker_processes 10;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid /var/run/nginx.pid;#Specifies
10、 the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 51200;eventsuse epoll;#maxclient = worker_processes * worker_connections / cpu_numberworker_connections 51200;include conf/mime.types;default_type application/octet-stream;log_format main $remote_addr - $
11、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;#sendfile on;tcp_nopush on;tcp_nodelay off;keepalive_timeout 60;client_header_timeout 3m;client_body_timeout 3m;send_timeout 3m;connection_pool_si
12、ze 256;client_header_buffer_size 1k;large_client_header_buffers 4 2k;request_pool_size 4k;output_buffers 4 32k;postpone_output 1460;client_max_body_size 10m;client_body_buffer_size 256k;client_body_temp_path /dev/shm/client_body_temp;proxy_temp_path /usr/local/nginx/proxy_temp;fastcgi_temp_path /usr
13、/local/nginx/fastcgi_temp;#gzipgzip on;gzip_http_version 1.0;gzip_comp_level 2;gzip_proxied any;gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml rss text/javascript;gzip_min_length 1100;gzip_buffers 4 8k;# The following includes are specified
14、 for virtual hosts /以下是加載虛擬主機配置.# HYPERLINK do-itnet.tk/blog/redocn t _blank redocninclude conf/vhosts/www_redocn_com.conf;#bbs.redocninclude conf/vhosts/bbs_redocn_com.conf;#blog.redocninclude conf/vhosts/blog_redocn_com.conf;#down.redocninclude conf/vhosts/down_redocn_com.conf;復制代碼2.配置支持Fastcgi方式的
15、PHProotredocn conf# cat enable_php5.conffastcgi_pass :8085;fastcgi_index index.php;fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx;#new ac upload#fastcgi_pass_request_body off;#client_body_in_file_only clean;#fastcgi_param REQUEST_BODY_FILE $request_body_file;#fastcgi_par
16、am 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 $
17、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;f
18、astcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;復制代碼四,多虛擬主機運用配置案例.#mkdir /usr/local/nginx/conf/vhosts /建立虛擬主機配置存放目錄.1.redocn /首站配置rootredocn vhosts#vi www_redocn_com.confserverlisten 80;server_name redocn;ind
19、ex index.html index.htm index.php;root /data/www/wwwroot;error_page 404 HYPERLINK bbs.redocn t _blank bbs.redocn;rewrite /bbs/(.*) HYPERLINK bbs.redocn/ t _blank bbs.redocn/$1;location .*.php?$include conf/enable_php5.conf;復制代碼注: 關于rewite需求,紅動中國希望當用戶訪問 HYPERLINK redocn/bbs t _blank redocn/bbs的時候自動轉至
20、 HYPERLINK bbs.redocn t _blank bbs.redocn在原apache中利用redirect實現(xiàn) Redirect /bbs HYPERLINK bbs.redocn t _blank bbs.redocn本文中在nginx下利用rewrite實現(xiàn):rewrite /bbs/(.*) HYPERLINK bbs.redocn/ t _blank bbs.redocn/$1;2.rootredocn vhosts vi bbs_redocn_com.confserverlisten 80;server_name bbs.redocn yan.redocn majia.
21、redocn wt.redocn;index index.html index.htm index.php;root /home/www/htdocs/bbs;access_log /var/log/nginx/access_bbs.redocn.log combined;location / #bbs rewriterewrite /archiver/(fid|tid)-w- .html)$ /archiver/index.php?$1 last;rewrite /forum-(0-9 )-(0-9 ).html$ /forumdisplay.php?fid=$1&page=$2 last;
22、rewrite /thread-(0-9 )-(0-9 )-(0-9 ).html$ /viewthread.php?tid=$1&extra=page=$3&page=$2 last;rewrite /space-(username|uid)-(. ).html$ /space.php?$1=$2 last;rewrite /tag-(. ).html$ /tag.php?name=$1 last;break;#errorerror_page 404 /index.php;#redirect server error pages to the static page /50 x.htmler
23、ror_page 500 502 503 504 /50 x.html;location = /50 x.html root html;#Preventing hot linking of images and other file typeslocation * . .(gif|jpg|png|swf|flv|rar|zip)$ valid_referers none blocked server_names*.redocn redocn *.taobao taobaobbs.blueidea bbs.asiaci bbs.arting365 forum.chinavisual softbb
24、s.pconlinebbs.chinaddu bbs.photops *.baidu *.google *.google *.soso *.yahoo*.yahoo;if ($invalid_referer) rewrite / HYPERLINK redocn/images/redocn.gif t _blank redocn/images/redocn.gif;#return 403;#support phplocation .*.php?$include conf/enable_php5.conf;復制代碼注:1.紅動中國采用高性能的Discuz!論壇,原apache的rewrite規(guī)那
25、么幾乎不要做什么修正即可全部移植到nginx下.靜態(tài)化配置見面上面的:#bbs rewrite部分.2.普通論壇都希望實現(xiàn)防盜鏈功能,在apache很輕松實現(xiàn)?在nginx下能否容易實現(xiàn)呢?答案是一定的. #Preventing hot linking of images and other file typesvalid_referers none blocked server_names *.redocn redocn 他允許銜接的網(wǎng)址;if ($invalid_referer) rewrite / HYPERLINK redocn/images/redocn.gif t _blank r
26、edocn/images/redocn.gif; /讓他人盜鏈時顯示他指定的圖片.#return 403;復制代碼3.blog.redocnrootredocn vhosts#vi blog_redocn_com.confserverlisten 80;server_name blog.redocn;index index.html index.htm index.php;root /data/www/wwwroot/blog;error_page 404 HYPERLINK bbs.redocn t _blank bbs.redocn;#supsite rewriterewrite (0-9
27、 )/spacelist(.*)$ index.php?$1/action_spacelist$2;rewrite (0-9 )/viewspace_(. )$ index.php?$1/action_viewspace_itemid_$2;rewrite (0-9 )/viewbbs_(. )$ index.php?$1/action_viewbbs_tid_$2;rewrite (0-9 )/(.*)$ index.php?$1/$2;rewrite (0-9 )$ index.php?$1;rewrite action_(. )$ index.php?action_$1;rewrite
28、category_(. )$ index.php?action_category_catid_$1;rewrite itemlist_(. )$ index.php?action_itemlist_catid_$1;rewrite viewnews_(. )$ index.php?action_viewnews_itemid_$1;rewrite viewthread_(. )$ index.php?action_viewthread_tid_$1;rewrite index(.a-zA-Z0-9*)$ index.php;rewrite html/(0-9 )/viewnews_itemid
29、_(0-9 ).html$ index.php?action_viewnews_itemid_$2;rewrite /(0-9 )/spacelist(. )$ /index.php?uid/$1/action/spacelist/type$2;rewrite /(0-9 )/viewspace(. )$ /index.php?uid/$1/action/viewspace/itemid$2;rewrite /(0-9 )/viewbbs(. )$ /index.php?uid/$1/action/viewbbs/tid$2;rewrite /(0-9 )/(.*)$ /index.php?u
30、id/$1/$2;rewrite /(0-9 )$ /index.php?uid/$1;rewrite /action(. )$ /index.php?action$1;rewrite /category(. )$ /index.php?action/category/catid$1;rewrite /viewnews(. )$ /index.php?action/viewnews/itemid$1;rewrite /viewthread(. )$ /index.php?action/viewthread/tid$1;rewrite /mygroup(. )$ /index.php?actio
31、n/mygroup/gid$1;location .*.php?$include conf/enable_php5.conf;復制代碼注:blog采用功能強大的Supesite作為Blog站點: HYPERLINK supesite/ t _blank supesite/1.Blog如何在Nginx里實現(xiàn)靜態(tài)化,詳細設置見,上面的#supesite rewrite4.down.redocnrootredocn vhosts# vi down_redocn_com.conflimit_zone one $binary_remote_addr 10m;serverlisten 80;server_
32、name down.redocn;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 /50 x.htmlerror_page 500 502 503 504 /50 x.html;location = /50 x.html root html;#Zone limitlocation / limit_conn one 1;limit_rate 20k;# serve static fileslocation /(images|javascript|js|css|flash|media|static)/ root /data/www/wwwroot/down;expires 30d;復制代碼注:由于如今的BT下載軟件越來越多了,我們如何限制下載的并發(fā)數(shù)和速率呢?apache
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 遼寧鐵道職業(yè)技術學院《視頻拍攝與編輯》2023-2024學年第二學期期末試卷
- 漯河食品職業(yè)學院《學術英語寫作(雙語)》2023-2024學年第二學期期末試卷
- 馬鞍山職業(yè)技術學院《天人合和:中醫(yī)養(yǎng)生與亞健康》2023-2024學年第二學期期末試卷
- 湖北水利水電職業(yè)技術學院《英語在線閱讀2》2023-2024學年第二學期期末試卷
- 浙江特殊教育職業(yè)學院《食品加工與制造》2023-2024學年第二學期期末試卷
- 遵義醫(yī)藥高等??茖W?!洞髮W英語D》2023-2024學年第二學期期末試卷
- 紹興文理學院《證據(jù)法》2023-2024學年第二學期期末試卷
- 孤獨的小螃蟹閱讀測試題及答案
- 公共交通服務設施維護制度
- 工作場所安全警示標志
- JJF 2119-2024 低氣壓試驗箱校準規(guī)范
- JBT 14727-2023 滾動軸承 零件黑色氧化處理 技術規(guī)范 (正式版)
- JBT 8127-2011 內燃機 燃油加熱器
- 2024年江蘇醫(yī)藥職業(yè)學院單招職業(yè)適應性測試題庫帶答案
- 辦公區(qū)域主要風險辨識與分級管控清單
- GB/T 43869-2024船舶交通管理系統(tǒng)監(jiān)視雷達通用技術要求
- JB∕T 8527-2015 金屬密封蝶閥
- 中醫(yī)培訓課件:《中藥封包技術》
- SYT5405-2019酸化用緩蝕劑性能試驗方法及評價指標
- 2024年遼寧鐵道職業(yè)技術學院單招職業(yè)技能測試題庫及答案解析
- 內鏡下內痔套扎治療
評論
0/150
提交評論