


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Web服務(wù)器nginx虛擬主機(jī)與反向代理web 服務(wù)器 -nginxweb服務(wù)器簡介:apache , web服務(wù)器:訪問網(wǎng)頁,查找、瀏覽信息。蜘蛛程序一網(wǎng)絡(luò)爬蟲常見的web服務(wù)器:apachelighttpdn gi nxtomcatIIS介紹nginx :高性能的http服務(wù)器和反向代理服務(wù)器(web加速),運(yùn)行在類unix和windows上為什么選擇 nginx ?處理速度快,占用的資源少apache里的模塊是動(dòng)、靜結(jié)合;在nginx里面,都是靜態(tài)的。支持熱部署可以7x24不間斷運(yùn)行書寫的代碼質(zhì)量很高,也很規(guī)范問題:俄國人寫的,一些官方資料,文檔比較少。安裝之前:1、準(zhǔn)備工作:1) ap
2、ache是停止的,釋放80端口nginx2) 添加一個(gè)普通用戶,出于安全的目的使用這個(gè)普通用戶去運(yùn)行# useradd -M -s /sbin/no logi n www默認(rèn)使用的是nobody 這個(gè)用戶。2、開始安裝rootlocalhost l nmp# tar zxvf n gi nx-x.tar.gz -C /usr/local/src/安裝nginx所需的軟件包支持正則表達(dá)式(1) PCRE: Perl 庫,Perl Compatible Regular Expressionsrootlocalhost nginx# cd pcre-8.10rootlocalhost pcre-8.
3、10# lsrootlocalhost pcre-8.10# ./c on figurerootlocalhost pcre-8.10# makerootlocalhost pcre-8.10# make in stall(2)安裝 nginxrootlocalhostngi nx-0.8.46#./c on figure-user=www-group=www-prefix=/usr/local/ngi nx-with-http_stub_status_module -with-http_ssl_module-user-group-prefix-with-http_stub_status_mo
4、dule狀態(tài)模塊-with-http_ssl_module支持 httpsyum in stall -y ope nssl-develrootlocalhost nginx-0.8.46# makerootlocalhost ngi nx-0.8.46# make in stallrootlocalhost nginx-0.8.46# cd /usr/local/nginx/rootlocalhost ngin x# lsconf html logs sbin啟動(dòng)服務(wù):rootlocalhost n gi nx# ./sb in/nginx -c conf/ngin x.c onfrootlo
5、calhost nginx# n etstat -antp | grep 80tcp00 :80:* LISTEN 19449/ngi nx.c onf訪問:Welcome to nginx! OK解讀配置文件:rootlocalhost conf# pwd/usr/local/nginx/confrootlocalhost conf# vim ngin x.c onf12 user www;3 worker_processes 1; #開啟的進(jìn)程數(shù),與 CPU的核數(shù)一致,查看CPU的信息:rootlocalhost html# cat /proc/cpu info
6、5 #error_log logs/error.log;錯(cuò)誤日志6 #error_log logs/error.log no tice;7 #error_log logs/error.log info;redhat 5man 5 syslog.c onfredhat 6man 5 rsyslog.c onf ?9 #pidlogs/ngi nx.pid;*12 events 13 use epoll;#指定nginx使用高效的工作模式14 worker_connections1024;#每個(gè)進(jìn)程能夠處理的最大連接數(shù)15 能夠處理的最大連接數(shù)=worker_processes x worker_
7、c onnectionsuse epoll; 指定nginx的工作模式默認(rèn)使用的是select和pollepoll 2.6內(nèi)核之后,某些發(fā)行版,比如SUSE、redhat支持epoll模型# un ame -rlinux 和redhat 和 windows 有沒有可比性?其他的發(fā)行版,要想使用高效模式:kqueue BSD系列MacOS等# cat /etc/issueRed Hat En terprise Li nux Server release 5.5 (Tika nga)18http 192022-26282931323436373839404142in eludemime.types
8、;#文件的擴(kuò)展名和文件類型default_type applicatio n/octet-stream; #文件的類型默認(rèn)是二進(jìn)制訪問日志sen dfileon;#開啟高效的文件傳輸模式#tcp_nopushon; #防止網(wǎng)絡(luò)阻塞#keepalive_timeout 0;#長連接的超時(shí)時(shí)間,秒keepalive_timeout65;#gzip on;#開啟gzip壓縮傳輸數(shù)據(jù)server liste n80;server_ namelocalhost;#charset koi8-r; # 字符集#access_log logs/host.access .log main;4344 locati
9、on / 45 root html; = docume ntroot46 in dexin dex.html in dex.htm;頁面文件的名字47 虛擬主機(jī):基于域名的虛擬主機(jī)。FQDNDocume ntrootww1. ngi /htdocs/ww1ww2. ngi /htdocs/ww2default/htdocs/default- /logs(raidO)日志遷移: 從 /usr/local/nginx/logs# mkdir -p /htdocs/ww1,ww2,default -v注意權(quán)限: www 進(jìn)去 xrootlocalhost conf# cd /htdocs/ww1ro
10、otlocalhost ww1# echo ww1. ngin in dex.htmlrootlocalhost ww1# cd ./ww2rootlocalhost ww2# echo ww2. ngin in dex.htmlrootlocalhost ww2# cd ./default/rootlocalhost default# echo default .ngin in dex.html測試配置文件是否正確:rootlocalhost ngin x# ./sb in/nginx-tthe configuration file /usr/local/nginx/conf/nginx.c
11、onf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful重啟:用kill命令給nginx的pid傳遞一個(gè)信號,讓它重新讀取配置文件rootlocalhost n gi nx# cat logs/ngin x.pid19449nginx的平滑重啟:rootlocalhost nginx# kill -HUP 19449客戶端測試:vim /etc/hosts添加53ww1. ngi 53ww2. ngi 打開瀏覽器:. ngi ww1.
12、ngin . ngin ww2. ngin /default .ngin nginx的日志管理錯(cuò)誤日志:nginx出問題,查看錯(cuò)誤日志,排錯(cuò)訪問日志:查看有哪些客戶端來訪問自己log_format ww1 $remote_addr - $remote_user $time_local $request$status $body_bytes_se nt $http_referer$http_user_age nt $http_x_forwarded_for;access_log logs/ww1.log ww1;1. Iog_format指定日志的格式log_format n ame forma
13、t$remote_addr 禾口 $http_x_forwarded_for: i己錄 ip 地址 *$remote_user :記錄客戶端的用戶名稱$time_local :記錄訪問時(shí)間和時(shí)區(qū)*$request :記錄請求的URL和HTTP協(xié)議$status :記錄請求狀態(tài)$body_bytes_sent:記錄發(fā)送給客戶端的文件的主體內(nèi)容的大小$http_referer :記錄從哪個(gè)頁面鏈接過來的$http_user_age nt :記錄客戶端瀏覽器的信息2. access_log指定日志的存放路徑問題:日志輪替寫一個(gè)日志輪替的腳本,結(jié)合計(jì)劃任務(wù)。1周替換一個(gè)新的日志文件?農(nóng)場和斗地主斗地主
14、:server ip : rootlocalhost si# yum in stall -y httpd mysql-server php php-mysqlrootlocalhost html# pwd/var/www/htmlrootlocalhost html# lsddzrootlocalhost html# chmod -R 777 ddz/rootlocalhost html# /etc/i nit.d/mysqld startmysql create database ddz;mysql grant all on ddz.* to ddzuserlocalhost identif
15、ied by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/c on f/httpd.co nfrootlocalhost html# /etc/i nit.d/httpd restart網(wǎng)頁安裝:服務(wù)器:localhost數(shù)據(jù)庫:ddzDB 帳號:ddzuserDB 密碼:123456QQ農(nóng)場:server ip : rootlocalhost s1# yum in stall -y httpd mysql-server php php-mysqlrootlocalhost Desktop# lsf
16、lash-plugin-5-release.i386.rpmqq 農(nóng)場.ziprootlocalhost Desktop# unzip qq 農(nóng)場.zip -d /var/www/html/rootlocalhost html# pwd/var/www/htmlrootlocalhost html# mv upload/ qqrootlocalhost html# Isddz qqrootlocalhost html# chmod -R 777 qqrootlocalhost html# /etc/i nit.d/mysqld startmysql create datab
17、ase qq;mysql grant all on qq.* to qquserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/c on f/httpd.co nfrootlocalhost html# /etc/i nit.d/httpd restartrootlocalhost qq# pwd/var/www/html/qqrootlocalhost qq# mysql qq 靜態(tài)頁面 index.html/htdocs/ww1/i ndex.html
18、location /index.html寫在虛擬主機(jī)里:location /index.html deny all;寫完了別忘了重啟服務(wù)。location /index.html return 404;location /.*.html$ return 404;rootlocalhost ww1# pwd/htdocs/ww1rootlocalhost ww1# lsin dex.htmlrootlocalhost ww1# echo 123 123.htmlrootlocalhost ww1# echo 456 456.htmllocation /123.html rewrite A/123
19、.html$ . ngi in dex.jsp asp?asdhka903249871fsdain dex.jsp?.*反向代理+負(fù)載均衡軟件7層 負(fù)載均衡:nginxL7SW( layer 7 )酉己置nginx :http upstream uplook #定義一個(gè) server_pool , 里面有一組服務(wù)器server 02;#這是 3 個(gè) apache 的 ipserver 03;server 04;server liste n80;locati on / proxy_pass;timeoutproxy_ next_u
20、pstreamhttp_500 http_502 http_503 errorin valid_header;in elude /usr/local/ngi nx/con f/proxy.c onf;rootlocalhost conf# vim proxy.c onfproxy_redirect off;proxy_set_header Host $host;#設(shè)置由后端服務(wù)器獲取用戶的主機(jī)名ip地址proxy_set_header X-Real_IP $remote_addr;#設(shè)置后端服務(wù)器獲取用戶的真實(shí)proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#設(shè)置有后端服務(wù)器獲取代理者的真實(shí)ipclie nt_body_buffer_size 128k;#用于指疋客戶端請求主體緩沖區(qū)大小proxy_c onn
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 家具制造業(yè)原材料價(jià)格波動(dòng)應(yīng)對2025年產(chǎn)業(yè)鏈整合策略報(bào)告
- 2025年醫(yī)藥流通企業(yè)供應(yīng)鏈優(yōu)化與成本控制創(chuàng)新策略報(bào)告
- 特色農(nóng)產(chǎn)品冷鏈物流中心建設(shè)對農(nóng)村經(jīng)濟(jì)發(fā)展的推動(dòng)作用報(bào)告
- 新能源商用車型號2025年市場需求與電動(dòng)物流車售后服務(wù)滿意度研究報(bào)告
- 磅房安全培訓(xùn)試題及答案
- 傳統(tǒng)食品工業(yè)化生產(chǎn)2025年智能檢測技術(shù)改造與創(chuàng)新案例報(bào)告
- 安全生產(chǎn)管理知識試題及答案
- 快時(shí)尚行業(yè)在2025年時(shí)尚零售市場中的品牌合作與跨界營銷報(bào)告
- 2025年土壤污染修復(fù)技術(shù)土壤修復(fù)藥劑市場發(fā)展趨勢報(bào)告
- 電泳工藝原理培訓(xùn)課件
- 印刷采購服務(wù)整體供貨實(shí)施方案
- 慢性阻塞性肺疾病診治指南通用課件
- 學(xué)校食堂食品安全事故應(yīng)急處置知識培訓(xùn)課件
- 《鋼筋及焊接件》課件
- 山東大學(xué)2022-2023學(xué)年第二學(xué)期高等數(shù)學(xué)Ⅰ(下)期末統(tǒng)考試題及答案解析
- 展示體驗(yàn)建筑設(shè)計(jì)中英文對照外文翻譯文獻(xiàn)
- 《數(shù)字化測圖》教學(xué)教案
- 美容外科注射美容技術(shù)操作規(guī)范2023版
- 基于UML的外賣訂餐系統(tǒng)需求分析
- 地溝供熱管網(wǎng)施工方案
- 東周戰(zhàn)爭與儒法國家的誕生
評論
0/150
提交評論