Web服務(wù)器nginx虛擬主機與反向代理.doc_第1頁
Web服務(wù)器nginx虛擬主機與反向代理.doc_第2頁
Web服務(wù)器nginx虛擬主機與反向代理.doc_第3頁
Web服務(wù)器nginx虛擬主機與反向代理.doc_第4頁
Web服務(wù)器nginx虛擬主機與反向代理.doc_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

Web服務(wù)器nginx虛擬主機與反向代理web 服務(wù)器 - nginxweb服務(wù)器簡介: apache,web服務(wù)器:訪問網(wǎng)頁,查找、瀏覽信息。蜘蛛程序網(wǎng)絡(luò)爬蟲常見的web服務(wù)器:apachelighttpdnginxtomcatIIS介紹nginx: 高性能的http服務(wù)器和反向代理服務(wù)器(web加速),運行在類unix和windows上為什么選擇nginx? 處理速度快,占用的資源少 apache里的模塊是動、靜結(jié)合;在nginx里面,都是靜態(tài)的。 支持熱部署 可以 7x24 不間斷運行 書寫的代碼質(zhì)量很高,也很規(guī)范問題:俄國人寫的,一些官方資料,文檔比較少。=安裝之前:1、準(zhǔn)備工作: 1)apache是停止的,釋放80端口 2)添加一個普通用戶,出于安全的目的使用這個普通用戶去運行nginx# useradd -M -s /sbin/nologin www默認(rèn)使用的是 nobody 這個用戶。2、開始安裝rootlocalhost lnmp# ls nginx-x.tar.gz nginx-x.tar.gzrootlocalhost lnmp# tar zxvf nginx-x.tar.gz -C /usr/local/src/安裝nginx所需的軟件包:pcre-8.10.tar.gznginx-0.8.46.tar.gz(1)PCRE:Perl庫, 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# ./configure rootlocalhost pcre-8.10# makerootlocalhost pcre-8.10# make install(2)安裝 nginxrootlocalhost nginx# ls nginx-0.8.46.tar.gz nginx-0.8.46.tar.gzrootlocalhost nginx# tar zxvf nginx-0.8.46.tar.gz rootlocalhost nginx-0.8.46# ./configure -user=www -group=www -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module-user-group-prefix-with-http_stub_status_module 狀態(tài)模塊-with-http_ssl_module支持 httpsyum install -y openssl-develrootlocalhost nginx-0.8.46# make rootlocalhost nginx-0.8.46# make installrootlocalhost nginx-0.8.46# cd /usr/local/nginx/rootlocalhost nginx# lsconf html logs sbin啟動服務(wù):rootlocalhost nginx# ./sbin/nginx -c conf/nginx.confrootlocalhost nginx# netstat -antp | grep 80tcp 0 0 :80 :* LISTEN 19449/nginx.conf 訪問:53/Welcome to nginx!OK解讀配置文件:rootlocalhost conf# pwd/usr/local/nginx/confrootlocalhost conf# vim nginx.conf 1 2 user www; 3 worker_processes 1; #開啟的進(jìn)程數(shù),與 CPU的核數(shù)一致,查看CPU的信息:rootlocalhost html# cat /proc/cpuinfo 5 #error_log logs/error.log;錯誤日志 6 #error_log logs/error.log notice; 7 #error_log logs/error.log info;redhat 5 man 5 syslog.confredhat 6 man 5 rsyslog.conf ? 9 #pid logs/nginx.pid; 12 events 13 use epoll;#指定nginx使用高效的工作模式 14 worker_connections 1024; # 每個進(jìn)程能夠處理的最大連接數(shù) 15 能夠處理的最大連接數(shù)=worker_processes x worker_connectionsuse epoll; 指定nginx的工作模式默認(rèn)使用的是 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) 18 http 19 include mime.types; #文件的擴展名和文件類型 20 default_type application/octet-stream; #文件的類型默認(rèn)是二進(jìn)制 22-26 訪問日志 28 sendfile on;#開啟高效的文件傳輸模式 29 #tcp_nopush on;#防止網(wǎng)絡(luò)阻塞 31 #keepalive_timeout 0;#長連接的超時時間,秒 32 keepalive_timeout 65; 34 #gzip on;#開啟gzip壓縮傳輸數(shù)據(jù) 36 server 37 listen 80; 38 server_name localhost; 39 40 #charset koi8-r;#字符集 41 42 #access_log logs/host.access.log main; 43 44 location / 45 root html;= documentroot 46 index index.html index.htm;頁面文件的名字 47 虛擬主機:基于域名的虛擬主機。FQDND/htdocs//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.htmlrootlocalhost ww1# cd ./ww2rootlocalhost ww2# echo index.htmlrootlocalhost ww2# cd ./default/rootlocalhost default# echo index.html測試配置文件是否正確:rootlocalhost nginx# ./sbin/nginx -tthe configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful重啟:用 kill 命令 給 nginx 的pid 傳遞一個信號,讓它重新讀取配置文件。rootlocalhost nginx# cat logs/nginx.pid 19449nginx的平滑重啟:rootlocalhost nginx# kill -HUP 19449客戶端測試:vim /etc/hosts添加53 53 打開瀏覽器://53/-nginx的日志管理- 錯誤日志:nginx出問題,查看錯誤日志,排錯 訪問日志:查看有哪些客戶端來訪問自己log_format 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;1. log_format 指定日志的格式log_format name format$remote_addr和$http_x_forwarded_for:記錄ip地址$remote_user:記錄客戶端的用戶名稱$time_local:記錄訪問時間和時區(qū)$request:記錄請求的URL和HTTP協(xié)議$status :記錄請求狀態(tài)$body_bytes_sent :記錄發(fā)送給客戶端的文件的主體內(nèi)容的大小$http_referer:記錄從哪個頁面鏈接過來的$http_user_agent:記錄客戶端瀏覽器的信息2. access_log 指定日志的存放路徑問題:日志輪替寫一個日志輪替的腳本,結(jié)合計劃任務(wù)。1周替換一個新的日志文件?-農(nóng)場和斗地主:-斗地主:server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php php-mysqlrootlocalhost html# pwd/var/www/htmlrootlocalhost html# lsddzrootlocalhost 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/httpd/conf/httpd.confDirectoryIndex index.php index.html index.html.varrootlocalhost html# /etc/init.d/httpd restart網(wǎng)頁安裝:21/ddz/install.php服務(wù)器:localhost數(shù)據(jù)庫:ddzDB帳號:ddzuserDB密碼:123456QQ農(nóng)場:server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php php-mysqlrootlocalhost Desktop# lsflash-plugin-5-release.i386.rpm qq農(nóng)場.ziprootlocalhost Desktop# unzip qq農(nóng)場.zip -d /var/www/html/rootlocalhost html# pwd/var/www/htmlrootlocalhost html# mv upload/ qqrootlocalhost html# lsddz qqrootlocalhost html# chmod -R 777 qqrootlocalhost html# /etc/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# pwd/var/www/html/qqrootlocalhost qq# mysql qq 靜態(tài)頁面 index.html/htdocs/ww1/index.htmllocation /index.html 寫在虛擬主機里: location /index.html deny all; 寫完了別忘了重啟服務(wù)。 location /index.html return 404; location /.*.html$ return 404; rootlocalhost ww1# pwd/htdocs/ww1rootlocalhost ww1# lsindex.htmlrootlocalhost ww1# echo 123 123.htmlrootlocalhost ww1# echo 456 456.html location /123.html rewrite /123.html$ /456.html; index.jsp asp?asdhka903249871fsdaindex.jsp?.*=反向代理負(fù)載均衡軟件 7層 負(fù)載均衡:nginx L7SW( layer 7 )配置nginx:http . upstream uplook #定義一個 server_pool,里面有一組服務(wù)器 server 02;#這是3個apache的ip server 03; server 04; server listen 80; location / proxy_pass http:/uplook; proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header; include /usr/local/nginx/conf/proxy.conf; .rootlocalhost conf# vim proxy.confproxy_redirect off;proxy_set_header Host $host;#設(shè)置由后端服務(wù)器獲取用戶的主機名proxy_set_header X-Real_IP $remote_addr; #設(shè)置后端服務(wù)器獲取用戶的真實ip地址proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #設(shè)置有后端服務(wù)器獲取代理者的真實ipclient_b

溫馨提示

  • 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論