Web服務(wù)器nginx虛擬主機(jī)與反向代理_第1頁(yè)
Web服務(wù)器nginx虛擬主機(jī)與反向代理_第2頁(yè)
Web服務(wù)器nginx虛擬主機(jī)與反向代理_第3頁(yè)
Web服務(wù)器nginx虛擬主機(jī)與反向代理_第4頁(yè)
Web服務(wù)器nginx虛擬主機(jī)與反向代理_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、.word可編輯.Web服務(wù)器nginx虛擬主機(jī)與反向代理web 服務(wù)器 -nginxweb服務(wù)器簡(jiǎn)介:apache , web服務(wù)器:訪問網(wǎng)頁(yè),查找、瀏覽信息。蜘蛛程序一網(wǎng)絡(luò)爬蟲常見的web服務(wù)器:apachelighttpdnginxtomcatIIS介紹nginx :高性能的http服務(wù)器和反向代理服務(wù)器(web加速),運(yùn)行在類unix和windows上為什么選擇 nginx ?處理速度快,占用的資源少apache里的模塊是動(dòng)、靜結(jié)合;在nginx里面,都是靜態(tài)的。專業(yè).專注.word可編輯.支持熱部署可以7x24不間斷運(yùn)行書寫的代碼質(zhì)量很高,也很規(guī)范問題:俄國(guó)人寫的,一些官方資料,文檔

2、比較少。安裝之前:1、準(zhǔn)備工作:nginx1) apache是停止的,釋放80端口2)添加一個(gè)普通用戶,出于安全的目的使用這個(gè)普通用戶去運(yùn)行# useradd -M -s /sbin/nologin www默認(rèn)使用的是nobody 這個(gè)用戶。2、開始安裝rootlocalhost lnmp# ls nginx-x.tar.gznginx-x.tar.gzrootlocalhost lnmp# tar zxvf nginx-x.tar.gz -C /usr/local/src/專業(yè).專注.word可編輯.安裝nginx所需的軟件包:pcre-8.10.tar.gznginx-0.8.46.tar

3、.gz(1) PCRE: Perl 庫(kù),Perl Compatible Regular Expressions支持正則表達(dá)式rootlocalhost nginx# tar zxvf pcre-8.10.tar.gzrootlocalhost nginx# cd pcre-8.10rootlocalhost pcre-8.10# lsrootlocalhost pcre-8.10# ./configurerootlocalhost pcre-8.10# makerootlocalhost pcre-8.10# make install(2)安裝 nginxrootlocalhost nginx

4、# ls nginx-0.8.46.tar.gznginx-0.8.46.tar.gzrootlocalhost nginx# tar zxvf nginx-0.8.46.tar.gzrootlocalhost nginx-0.8.46# ./configure -user=www -group=www專業(yè).專注.word可編輯.-prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module-user-group-prefix-with-http_stub_status_module狀態(tài)模塊-with-h

5、ttp_ssl_module支持 httpsyum install -y openssl-develrootlocalhost nginx-0.8.46# makerootlocalhost nginx-0.8.46# make installrootlocalhost nginx-0.8.46# cd /usr/local/nginx/rootlocalhost nginx# lsconf html logs sbin啟動(dòng)服務(wù):rootlocalhost nginx# ./sbin/nginx -c conf/nginx.confrootlocalhost nginx# netstat -a

6、ntp | grep 80tcp00 :80:* LISTEN 19449/nginx.conf專業(yè).專注.word可編輯.訪問:http:53/Welcome to nginx! OK解讀配置文件:rootlocalhost conf# pwd/usr/local/nginx/confrootlocalhost conf# vim nginx.conf1user www;worker_processes 1; #開啟的進(jìn)程數(shù),與 CPU的核數(shù)一致,查看CPU的信息:rootlocalhost html# cat /proc/cpuinfo#error_log logs/error.log;錯(cuò)

7、誤日志#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;redhat 5man 5 syslog.confredhat 6man 5 rsyslog.conf ?專業(yè).專注.word可編輯.#pidlogs/nginx.pid; * *events use epoll;#指定nginx使用高效的工作模式worker_connections 1024;#每個(gè)進(jìn)程能夠處理的最大連接數(shù)能夠處理的最大連接數(shù)=worker_processes x worker_connectionsuse epoll; 指定nginx的工作模式默認(rèn)使

8、用的是select和pollepoll 2.6內(nèi)核之后,某些發(fā)行版,比如SUSE、redhat支持epoll模型uname -r2.6.18-194.el5linux 和redhat 和 windows 有沒有可比性?其他的發(fā)行版,要想使用高效模式:kqueue BSD系列MacOS等cat /etc/issueRed Hat Enterprise Linux Server release 5.5 (Tikanga)專業(yè).專注.word可編輯.18 http 192022-26282931323436373839404142includemime.types;#文件的擴(kuò)展名和文件類型defau

9、lt_type application/octet-stream; #文件的類型默認(rèn)是二進(jìn)制訪問日志sendfileon; #開啟高效的文件傳輸模式#tcp_nopush on;#防止網(wǎng)絡(luò)阻塞#keepalive_timeout 0;#長(zhǎng)連接的超時(shí)時(shí)間,秒keepalive_timeout65;#gzip on;#開啟gzip壓縮傳輸數(shù)據(jù)server listen80;server_name localhost;#charset koi8-r; # 字符集#access_log logs/host.access.log main;專業(yè).專注.word可編輯.43location / rooth

10、tml; = documentrootindexindex.html index.htm;頁(yè)面文件的名字虛擬主機(jī):基于域名的虛擬主機(jī)。FQDNDocumentroot/htdocs/ww1/htdocs/ww2default/htdocs/default日志遷移:從 /usr/local/nginx/logs - /logs(raid0)# mkdir -p /htdocs/ww1,ww2,default -v注意權(quán)限: www 進(jìn)去 xrootlocalhost conf# cd /htdocs/ww1rootlocalhost ww1# echo index.html專業(yè).專注.word可

11、編輯.rootlocalhost ww1# cd ./ww2rootlocalhost ww2# echo index.htmlrootlocalhost ww2# cd ./default/rootlocalhost default# echo index.html測(cè)試配置文件是否正確:rootlocalhost nginx# ./sbin/nginx -tthe configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf

12、 test is successful重啟:用kill命令給nginx的pid傳遞一個(gè)信號(hào),讓它重新讀取配置文件rootlocalhost nginx# cat logs/nginx.pid19449 nginx的平滑重啟:rootlocalhost nginx# kill -HUP 19449客戶端測(cè)試:vim /etc/hosts添加專業(yè).專注.word可編輯.5353打開瀏覽器: HYPERLINK / / HYPERLINK / / HYPERLINK 53/ 53/nginx的日志管理錯(cuò)誤日志:nginx出問題,查看錯(cuò)誤日志,排錯(cuò)訪問日志:查看有哪些客戶端來(lái)訪問自己log_forma

13、t ww1 $remote_addr - $remote_user $time_local $request$status $body_bytes_sent $http_referer$http_user_agent $http_x_forwarded_for;access_log logs/ww1.log ww1;專業(yè).專注.word可編輯.log_format 指定日志的格式log_format name format$remote_addr 和 $http_x_forwarded_for : t己錄 ip 地址 *$remote_user :記錄客戶端的用戶名稱$time_local :

14、記錄訪問時(shí)間和時(shí)區(qū) *$request :記錄請(qǐng)求的URL和HTTP協(xié)議$status :記錄請(qǐng)求狀態(tài)$body_bytes_sent :記錄發(fā)送給客戶端的文件的主體內(nèi)容的大小$http_referer :記錄從哪個(gè)頁(yè)面鏈接過來(lái)的$http_user_agent :記錄客戶端瀏覽器的信息access_log指定日志的存放路徑問題:日志輪替寫一個(gè)日志輪替的腳本,結(jié)合計(jì)劃任務(wù)。1周替換一個(gè)新的日志文件?農(nóng)場(chǎng)和斗地主專業(yè).專注.word可編輯.斗地主:server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php php-m

15、ysqlrootlocalhost html# pwd/var/www/htmlrootlocalhost html# ls ddzrootlocalhost html# chmod -R 777 ddz/rootlocalhost html# /etc/init.d/mysqld startmysql create database ddz;mysql grant all on ddz.* to ddzuserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/http

16、d/conf/httpd.confDirectoryIndex index.php index.html index.html.var專業(yè).專注.word可編輯.rootlocalhost html# /etc/init.d/httpd restart網(wǎng)頁(yè)安裝: HYPERLINK 21/ddz/install.php 21/ddz/install.php服務(wù)器:localhost數(shù)據(jù)庫(kù):ddzDB 帳號(hào):ddzuserDB 密碼:123456QQ農(nóng)場(chǎng):server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php p

17、hp-mysqlrootlocalhost Desktop# lsflash-plugin-5-release.i386.rpm qq 農(nóng)場(chǎng).ziprootlocalhost Desktop# unzip qq 農(nóng)場(chǎng).zip -d /var/www/html/rootlocalhost html# pwd/var/www/html專業(yè).專注.word可編輯.rootlocalhost html# mv upload/ qqrootlocalhost html# lsddz qqrootlocalhost html# chmod -R 777 qqrootlocalhost html# /etc

18、/init.d/mysqld startmysql create database qq;mysql grant all on qq.* to qquserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/conf/httpd.confDirectoryindex index.php index.html index.html.varrootlocalhost html# /etc/init.d/httpd restartrootlocalhost qq#

19、pwd/var/www/html/qqrootlocalhost qq# mysql qq 靜態(tài)頁(yè)面 index.html/htdocs/ww1/index.htmllocation /index.html寫在虛擬主機(jī)里:location /index.html deny all;寫完了別忘了重啟服務(wù)。專業(yè).專注.word可編輯.location /index.html return 404;)location /.*.html$ return 404;)rootlocalhost ww1# pwd/htdocs/ww1rootlocalhost ww1# lsindex.htmlrootlo

20、calhost ww1# echo 123 123.htmlrootlocalhost ww1# echo 456 456.htmllocation /123.html rewrite A/123.html$ HYPERLINK /456.html /456.html;)index.jsp asp?asdhka903249871fsdaindex.jsp?.*專業(yè).專注.word可編輯.反向代理+負(fù)載均衡軟彳7層 負(fù)載均衡:nginx L7SW( layer 7 )配置nginx :http (upstream uplook #定義一個(gè) server_pool , 里面有一組服務(wù)器server

21、 02;#這是 3 個(gè) apache 的 ipserver 03;server 04;server listen80;location / proxy_passhttp:uplook;timeoutproxy_next_upstream http_500 http_502 http_503 error invalid_header;專業(yè).專注.word可編輯.include /usr/local/nginx/conf/proxy.conf;rootlocalhost conf# vim proxy.conf proxy_redirect off;proxy_set_header Host $host;#設(shè)置由后端服務(wù)器獲取用戶的主機(jī)名proxy_set_header X-Real_IP $remote_addr;#設(shè)置后端服務(wù)器獲取用戶的真實(shí)ip地址proxy_set_header X-Forwarded-Fo

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論