中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

上海網(wǎng)絡(luò)企業(yè)優(yōu)化公司seo是什么職業(yè)

上海網(wǎng)絡(luò)企業(yè)優(yōu)化公司,seo是什么職業(yè),山東網(wǎng)站建設(shè)網(wǎng)站推廣,org域名做網(wǎng)站nginx反向代理8.反向代理8.1 實現(xiàn)http反向代理8.1.1 反向代理配置參數(shù)8.1.2 反向代理單臺web服務(wù)器8.1.2.1 端口號后加"/"8.1.2.2 端口號后不加"/" 8.1.3指定location 實現(xiàn)反向代理,動靜分離8.1.4 反向代理實例:緩存功能8.1.4.1 舉例 8.1.5 實現(xiàn)…

  • nginx反向代理
    • 8.反向代理
      • 8.1 實現(xiàn)http反向代理
        • 8.1.1 反向代理配置參數(shù)
        • 8.1.2 反向代理單臺web服務(wù)器
          • 8.1.2.1 端口號后加"/"
          • 8.1.2.2 端口號后不加"/"
        • 8.1.3指定location 實現(xiàn)反向代理,動靜分離
        • 8.1.4 反向代理實例:緩存功能
          • 8.1.4.1 舉例
        • 8.1.5 實現(xiàn)反向代理客戶端 IP 透傳
          • 8.1.5.1 一級代理
          • 8.1.5.2 多級代理ip地址透傳

nginx反向代理

8.反向代理

8.1 實現(xiàn)http反向代理

官方文檔: https://nginx.org/en/docs/http/ngx_http_proxy_module.html

8.1.1 反向代理配置參數(shù)
#官方文檔:https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass 
proxy_pass; 
#用來設(shè)置將客戶端請求轉(zhuǎn)發(fā)給的后端服務(wù)器的主機,可以是主機名(將轉(zhuǎn)發(fā)至后端服務(wù)做為主機頭首部)、IP
地址:端口的方式
#也可以代理到預(yù)先設(shè)置的主機群組,需要模塊ngx_http_upstream_module支持#示例:location /web {index index.html;proxy_pass http://10.0.0.18:8080; #8080后面無uri,即無 / 符號,需要將location后面url 附加到proxy_pass指定的url后面,此行為類似于root
#proxy_pass指定的uri不帶斜線將訪問的/web,等于訪問后端服務(wù)器
http://10.0.0.18:8080/web/index.html,即后端服務(wù)器配置的站點根目錄要有web目錄才可以被訪問# http://nginx/web/index.html ==> http://10.0.0.18:8080/web/index.htmlproxy_pass http://10.0.0.18:8080/;   #8080后面有uri,即有 / 符號,相當(dāng)于置換,即訪問/web時實際返回proxy_pass后面uri內(nèi)容.此行為類似于alias #proxy_pass指定的uri帶斜線,等于訪問后端服務(wù)器的http://10.0.0.18:8080/index.html 內(nèi)容返回給客戶端}  # http://nginx/web/index.html ==> http://10.0.0.18:8080#重啟Nginx測試訪問效果:
#curl -L http://www.kgc.org/web#如果location定義其uri時使用了正則表達式模式(包括~,~*,但不包括^~),則proxy_pass之后必須不能使用uri; 即不能有/ ,用戶請求時傳遞的uri將直接附加至后端服務(wù)器之后
server {...server_name HOSTNAME;location ~|~* /uri/ {proxy_pass http://host:port; #proxy_pass后面的url 不能加/}...}http://HOSTNAME/uri/ --> http://host/uri/proxy_hide_header field;
#用于nginx作為反向代理的時候,在返回給客戶端http響應(yīng)時,隱藏后端服務(wù)器相應(yīng)頭部的信息,可以設(shè)置
在http,server或location塊
#示例: 隱藏后端服務(wù)器ETag首部字段location /web {index index.html;proxy_pass http://10.0.0.18:8080/; proxy_hide_header ETag;}proxy_pass_header field;
#默認nginx在響應(yīng)報文中不傳遞后端服務(wù)器的首部字段Date, Server, X-Pad, X-Accel等參數(shù),如果
要傳遞的話則要使用 proxy_pass_header field聲明將后端服務(wù)器返回的值傳遞給客戶端
#field 首部字段大小不敏感
#示例:透傳后端服務(wù)器的Server和Date首部給客戶端,同時不再響應(yīng)報中顯示前端服務(wù)器的Server字段
proxy_pass_header Server;
proxy_pass_header Date;proxy_pass_request_body on | off; 
#是否向后端服務(wù)器發(fā)送HTTP實體部分,可以設(shè)置在http,server或location塊,默認即為開啟proxy_pass_request_headers on | off; 
#是否將客戶端的請求頭部轉(zhuǎn)發(fā)給后端服務(wù)器,可以設(shè)置在http,server或location塊,默認即為開啟
8.1.2 反向代理單臺web服務(wù)器

要求:將用戶對域 www.pc.com的請求轉(zhuǎn)發(fā)給后端服務(wù)器處理

7-1
vim /apps/nginx/conf.d/pc.conf
location / {proxy_pass http://192.168.210.102; 
}
#添加此項,使訪問7-1可以跳轉(zhuǎn)到7-2nginx -s reload

在這里插入圖片描述

7-3
curl 192.168.210.101

在這里插入圖片描述

端口號問題,端口號轉(zhuǎn)的時候可以一起轉(zhuǎn)
7-1
vim /apps/nginx/conf.d/pc.conf
location / {proxy_pass http://192.168.210.102:9527; 
}
#添加端口號nginx  -s reload

在這里插入圖片描述

7-2
vim /apps/nginx/conf/nginx.conf
server {listen 80;listen 9527;#添加端口號9527
}nginx -s reload
ss -lntp | grep nginx

在這里插入圖片描述

在這里插入圖片描述

7-3
curl 192.168.210.101

在這里插入圖片描述

8.1.2.1 端口號后加"/"
7-1
vim /apps/nginx/conf.d/pc.conf
location /web {proxy_pass http://192.168.210.102:9527; 
}
#不加/,相當(dāng)于把/web追加到9527的后面,訪問的時候會報錯,因為7-2下沒有web文件夾nginx -s reload
7-2
cd /apps/nginx/html
mkdir web
#創(chuàng)建web文件夾
echo web > web/index.html

在這里插入圖片描述

7-3
curl 192.168.210.101/web -L

在這里插入圖片描述

8.1.2.2 端口號后不加"/"
7-1
vim /apps/nginx/conf.d/pc.conf
location /web {proxy_pass http://192.168.210.102:9527/; 
}
#加/,代表將location后面的url置換到后面
nginx -s reload
7-3
curl 192.168.210.101/web -L

在這里插入圖片描述

8.1.3指定location 實現(xiàn)反向代理,動靜分離
7-3(192.168.210.103)客戶端
7-1(192.168.210.101)反向代理
7-4(192.168.210.104)動態(tài)頁面
7-2(192.168.210.102)靜態(tài)頁面
7-4
systemctl stop firewalld
setenforce 0
#關(guān)閉防火墻
yum install httpd -y
#安裝apache
cd /var/www/html
echo httpd > index.html
#制作頁面
ls
cat index.html
systemctl start httpd
#開啟服務(wù)
7-1
vim /apps/nginx/conf.d/pc.conf
location /static {proxy_pass http://192.168.210.102:9527; 
}
location /api {proxy_pass http://192.168.210.104; 
}nginx -s reload

在這里插入圖片描述

7-4
cd /var/www/html
mkdir api
#創(chuàng)建文件夾api
echo api >> api/index.html
echo api >> api/index.html
echo api >> api/index.html
#制作動態(tài)頁面
cat api/index.html

在這里插入圖片描述

7-2 
cd /apps/nginx/html
mkdir static
#創(chuàng)建static文件夾
echo static >> static/index.html
echo static >> static/index.html
echo static >> static/index.html
#制作靜態(tài)頁面
cat static/index.html

在這里插入圖片描述

7-3
curl 192.168.210.101/api -L
curl 192.168.210.101/static -L
#實現(xiàn)動靜分離

在這里插入圖片描述

8.1.4 反向代理實例:緩存功能
proxy_cache zone_name | off; 默認off
#指明調(diào)用的緩存,或關(guān)閉緩存機制;Context:http, server, location
#zone_name 表示緩存的名稱.需要由proxy_cache_path事先定義proxy_cache_key string;
#緩存中用于“鍵”的內(nèi)容,默認值:proxy_cache_key $scheme$proxy_host$request_uri;proxy_cache_valid [code ...] time;
#定義對特定響應(yīng)碼的響應(yīng)內(nèi)容的緩存時長,定義在http{...}中示例:proxy_cache_valid 200 302 10m;proxy_cache_valid 404 1m;proxy_cache_path;
#定義可用于proxy功能的緩存;Context:http 
proxy_cache_path path [levels=levels] [use_temp_path=on|off] 
keys_zone=zone_name:size [inactive=time] [max_size=size] [manager_files=number] 
[manager_sleep=time] [manager_threshold=time] [loader_files=number] 
[loader_sleep=time] [loader_threshold=time] [purger=on|off] 
[purger_files=number] [purger_sleep=time] [purger_threshold=time];#示例:在http配置定義緩存信息proxy_cache_path /var/cache/nginx/proxy_cache #定義緩存保存路徑,proxy_cache會自動創(chuàng)建levels=1:2:2 #定義緩存目錄結(jié)構(gòu)層次,1:2:2可以生成2^4x2^8x2^8=2^20=1048576個目錄keys_zone=proxycache:20m #指內(nèi)存中緩存的大小,主要用于存放key和metadata(如:使用次數(shù)),一般1M可存放8000個左右的keyinactive=120s  #緩存有效時間  max_size=10g; #最大磁盤占用空間,磁盤存入文件內(nèi)容的緩存空間最大值#調(diào)用緩存功能,需要定義在相應(yīng)的配置段,如server{...};或者location等
proxy_cache proxycache;
proxy_cache_key $request_uri; #對指定的數(shù)據(jù)進行MD5的運算做為緩存的key
proxy_cache_valid 200 302 301 10m; #指定的狀態(tài)碼返回的數(shù)據(jù)緩存多長時間
proxy_cache_valid any 1m;   #除指定的狀態(tài)碼返回的數(shù)據(jù)以外的緩存多長時間,必須設(shè)置,否則不會緩存proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | 
http_502 | http_503 | http_504 | http_403 | http_404 | off ; #默認是off
#在被代理的后端服務(wù)器出現(xiàn)哪種情況下,可直接使用過期的緩存響應(yīng)客戶端
#示例
proxy_cache_use_stale error http_502 http_503;proxy_cache_methods GET | HEAD | POST ...;
#對哪些客戶端請求方法對應(yīng)的響應(yīng)進行緩存,GET和HEAD方法總是被緩存
8.1.4.1 舉例
7-1
vim /apps/nginx/conf/nginx.confproxy_cache_path /data/nginx/proyxcache   levels=1:1:1 keys_zone=proxycache:20m inactive=120s max_size=1g;
#加在include前mkdir /data/nginx
#創(chuàng)建nginx文件夾

在這里插入圖片描述

vim /apps/nginx/conf.d/pc.confserver{listen 80;proxy_cache proxycache;proxy_cache_key $request_uri;proxy_cache_valid 200 302 301 10m;proxy_cache_valid any 5m;}   nginx -tnginx -s reload

在這里插入圖片描述

 ls /data/nginx#看是否生成proyxcache文件
在瀏覽器訪問192.168.210.101

在這里插入圖片描述

關(guān)閉web服務(wù)器7-2,再次在瀏覽器訪問192.168.210.101
還能出來界面,說明有緩存

在這里插入圖片描述

8.1.5 實現(xiàn)反向代理客戶端 IP 透傳
8.1.5.1 一級代理

在這里插入圖片描述

7-1(192.168.210.101)代理服務(wù)器
7-2(192.168.210.102)web服務(wù)器
7-3(192.168.210.103)客戶端
7-2
yum install httpd -y
#安裝apache
cd /var/www/html
echo real server > index.html
#制作頁面
cat index.html
systemctl start httpd
ss -lntp |grep 80
#開啟服務(wù)

在這里插入圖片描述

7-1
vim /apps/nginx/conf.d/pc.conf
#刪掉這個location模塊
location /api {proxy_pass http://192.168.210.104; 
} 
nginx -t
nginx -s reload

在這里插入圖片描述

7-3 
curl 192.168.210.101

在這里插入圖片描述

7-2
tail -f /var/log/httpd/access_log
#只能看到192.168.210.101的日志,看不到192.168.210.103的
7-1
tail -f /apps/nginx/logs/access.log
#192.168.210.101可以看到192.168.210.103的日志

在這里插入圖片描述

7-1
vim /apps/nginx/conf.d/pc.confproxy_set_header test "$remote_addr";                  #往日志里面加了test,內(nèi)容是$remote_addr#$remote_addr只能記一次,如果中間是三層代理,它就無法去實現(xiàn)了
nginx -t
nginx -s reload

在這里插入圖片描述

7-2
vim /etc/httpd/conf/httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{test}i\"" combinedsystemctl restart httpd

在這里插入圖片描述

7-3
curl 192.168.210.1017-2
tail -f /var/log/httpd/access_log
#192.168.210.103的地址就過來了
8.1.5.2 多級代理ip地址透傳

在這里插入圖片描述

7-1
vim /apps/nginx/conf/nginx.conf
#把日志全都打開

在這里插入圖片描述

7-4
yum install -y epel-release
yum install nginx -y
7-1
scp /apps/nginx/conf.d/pc.conf  192.168.210.104:/etc/nginx
7-4
cd /etc/nginx
vim pc.conf
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#添加
nginx -t
systemctl start nginx

在這里插入圖片描述

7-1
vim /apps/nginx/conf.d/pc.conf
systemctl restart nginx

在這里插入圖片描述

7-2
vim /etc/httpd/conf/httpd.conf
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\"" combinedsystemctl restart httpd

在這里插入圖片描述

7-3 
curl 192.168.210.1017-1
tail -f /apps/nginx/logs/access.log
7-2
tail -f /var/log/httpd/access_log

在這里插入圖片描述
在這里插入圖片描述

http://www.risenshineclean.com/news/52390.html

相關(guān)文章:

  • azure做網(wǎng)站營銷型企業(yè)網(wǎng)站案例
  • 做的網(wǎng)站怎么發(fā)布武漢seo優(yōu)化公司
  • 電影網(wǎng)站加盟可以做么整站營銷系統(tǒng)
  • 企業(yè)建站公司哪里找最新的新聞 今天
  • 磁盤陣列做網(wǎng)站手機網(wǎng)站建設(shè)公司
  • wordpress隱藏地址插件西安seo霸屏
  • 自適應(yīng)網(wǎng)站什么意思網(wǎng)絡(luò)營銷策劃ppt
  • 蘇州實力做網(wǎng)站公司有哪些網(wǎng)站制作流程和方法
  • 集團網(wǎng)站建設(shè)哪家好谷歌搜索引擎入口2022
  • 做一些網(wǎng)站犯法么網(wǎng)站建設(shè)公司哪個好呀
  • 如何運營一個網(wǎng)站2024年1月新冠高峰期
  • 惠東做網(wǎng)站報價seo有名氣的優(yōu)化公司
  • 世界上有php應(yīng)用的網(wǎng)站seo點擊排名工具有用嗎
  • 深圳做棋牌網(wǎng)站建設(shè)哪家便宜今日疫情最新數(shù)據(jù)
  • 安裝兩個wordpressseozhun
  • 建設(shè)網(wǎng)站的必要與可行性seo優(yōu)
  • 廣州網(wǎng)站優(yōu)化關(guān)鍵詞公司百度收錄入口在哪里
  • 做網(wǎng)站有哪些平臺宣傳推廣方案
  • seo網(wǎng)站模版合肥百度seo排名
  • iis做的網(wǎng)站為啥打不開知了seo
  • 上海網(wǎng)站建設(shè)的seo網(wǎng)站優(yōu)化推廣怎么樣
  • 網(wǎng)站被別人做鏡像福州短視頻seo方法
  • 讓wordpress的頁面有具體的地址東莞百度快速排名優(yōu)化
  • 商務(wù)網(wǎng)站規(guī)劃與設(shè)計實訓(xùn)心得鏈交換
  • 水果網(wǎng)站建設(shè)案例免費宣傳平臺有哪些
  • 手機如何網(wǎng)站一級消防工程師考試
  • 做網(wǎng)站能傳電影網(wǎng)站多少錢百度指數(shù)數(shù)據(jù)分析
  • 新河網(wǎng)站建設(shè)關(guān)鍵詞資源
  • 哪些網(wǎng)站用.ren域名360推廣助手
  • 網(wǎng)站開發(fā)的測試內(nèi)容怎樣建立個人網(wǎng)站