Web服務器ngin虛擬主機與反向代理_第1頁
Web服務器ngin虛擬主機與反向代理_第2頁
Web服務器ngin虛擬主機與反向代理_第3頁
已閱讀5頁,還剩17頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Web服務器nginx虛擬主機與反向代理web 服務器 -nginxweb服務器簡介:apache , web服務器:訪問網頁,查找、瀏覽信息。蜘蛛程序一網絡爬蟲常見的web服務器:apachelighttpdn gi nxtomcatIIS介紹nginx :高性能的http服務器和反向代理服務器(web加速),運行在類unix和windows上為什么選擇 nginx ?處理速度快,占用的資源少apache里的模塊是動、靜結合;在nginx里面,都是靜態的。支持熱部署可以7x24不間斷運行書寫的代碼質量很高,也很規范問題:俄國人寫的,一些官方資料,文檔比較少。安裝之前:1、準備工作:1) ap

2、ache是停止的,釋放80端口nginx2) 添加一個普通用戶,出于安全的目的使用這個普通用戶去運行# useradd -M -s /sbin/no logi n www默認使用的是nobody 這個用戶。2、開始安裝rootlocalhost l nmp# tar zxvf n gi nx-x.tar.gz -C /usr/local/src/安裝nginx所需的軟件包支持正則表達式(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狀態模塊-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啟動服務: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; #開啟的進程數,與 CPU的核數一致,查看CPU的信息:rootlocalhost html# cat /proc/cpu info

6、5 #error_log logs/error.log;錯誤日志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;#每個進程能夠處理的最大連接數15 能夠處理的最大連接數=worker_processes x worker_

7、c onnectionsuse epoll; 指定nginx的工作模式默認使用的是select和pollepoll 2.6內核之后,某些發行版,比如SUSE、redhat支持epoll模型# un ame -rlinux 和redhat 和 windows 有沒有可比性?其他的發行版,要想使用高效模式:kqueue BSD系列MacOS等# cat /etc/issueRed Hat En terprise Li nux Server release 5.5 (Tika nga)18http 192022-26282931323436373839404142in eludemime.types

8、;#文件的擴展名和文件類型default_type applicatio n/octet-stream; #文件的類型默認是二進制訪問日志sen dfileon;#開啟高效的文件傳輸模式#tcp_nopushon; #防止網絡阻塞#keepalive_timeout 0;#長連接的超時時間,秒keepalive_timeout65;#gzip on;#開啟gzip壓縮傳輸數據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 虛擬主機:基于域名的虛擬主機。FQDNDocume ntrootww1. ngi /htdocs/ww1ww2. ngi /htdocs/ww2default/htdocs/default- /logs(raidO)日志遷移: 從 /usr/local/nginx/logs# mkdir -p /htdocs/ww1,ww2,default -v注意權限: www 進去 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傳遞一個信號,讓它重新讀取配置文件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的日志管理錯誤日志:nginx出問題,查看錯誤日志,排錯訪問日志:查看有哪些客戶端來訪問自己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 :記錄訪問時間和時區*$request :記錄請求的URL和HTTP協議$status :記錄請求狀態$body_bytes_sent:記錄發送給客戶端的文件的主體內容的大小$http_referer :記錄從哪個頁面鏈接過來的$http_user_age nt :記錄客戶端瀏覽器的信息2. access_log指定日志的存放路徑問題:日志輪替寫一個日志輪替的腳本,結合計劃任務。1周替換一個新的日志文件?農場和斗地主斗地主

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網頁安裝:服務器:localhost數據庫:ddzDB 帳號:ddzuserDB 密碼:123456QQ農場:server ip : rootlocalhost s1# yum in stall -y httpd mysql-server php php-mysqlrootlocalhost Desktop# lsf

16、lash-plugin-5-release.i386.rpmqq 農場.ziprootlocalhost Desktop# unzip qq 農場.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 靜態頁面 index.html/htdocs/ww1/i ndex.html

18、location /index.html寫在虛擬主機里:location /index.html deny all;寫完了別忘了重啟服務。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?.*反向代理+負載均衡軟件7層 負載均衡:nginxL7SW( layer 7 )酉己置nginx :http upstream uplook #定義一個 server_pool , 里面有一組服務器server 02;#這是 3 個 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;#設置由后端服務器獲取用戶的主機名ip地址proxy_set_header X-Real_IP $remote_addr;#設置后端服務器獲取用戶的真實proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#設置有后端服務器獲取代理者的真實ipclie nt_body_buffer_size 128k;#用于指疋客戶端請求主體緩沖區大小proxy_c onn

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論