最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx正向代理http和https的實現(xiàn)步驟

 更新時間:2023年07月09日 10:05:13   作者:qq_44659804  
本文主要介紹了nginx正向代理http和https的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

配置準(zhǔn)備

正向代理,指的是通過代理服務(wù)器 代理瀏覽器/客戶端去重定向請求訪問到目標(biāo)服務(wù)器 的一種代理服務(wù)。
正向代理服務(wù)的特點是代理服務(wù)器 代理的對象是瀏覽器/客戶端,也就是對于目標(biāo)服務(wù)器 來說瀏覽器/客戶端是隱藏的。

nginx默認(rèn)支持正向代理http,不支持https

nginx官方并不支持直接轉(zhuǎn)發(fā)https請求,nginx支持https需要ngx_http_proxy_connect_module模塊。github上開源了模塊 https://github.com/chobits/ngx_http_proxy_connect_module。不過維護(hù)的ngx_http_proxy_connect_module模塊的補(bǔ)丁也是有nginx版本限制的(目前維護(hù)了1.4.x~1.19.x版本)
可以在REDEME.md的Select patch中查看nginx版本和模塊的對應(yīng)關(guān)系

nginx版本和正向代理https的模塊的對應(yīng)關(guān)系

nginx versionenable REWRITE phasepatch
1.4.x ~ 1.12.xNOproxy_connect.patch
1.4.x ~ 1.12.xYESproxy_connect_rewrite.patch
1.13.x ~ 1.14.xNOproxy_connect_1014.patch
1.13.x ~ 1.14.xYESproxy_connect_rewrite_1014.patch
1.15.2YESproxy_connect_rewrite_1015.patch
1.15.4 ~ 1.16.xYESproxy_connect_rewrite_101504.patch
1.17.x ~ 1.18.0YESproxy_connect_rewrite_1018.patch
1.19.x ~ 1.21.0YESproxy_connect_rewrite_1018.patch
1.21.1 ~ 1.22.0YESproxy_connect_rewrite_102101.patch
ls /root/ngx_http_proxy_connect_module/patch
proxy_connect_1014.patch            proxy_connect_rewrite_1015.patch
proxy_connect.patch                 proxy_connect_rewrite_1018.patch
proxy_connect_rewrite_1014.patch    proxy_connect_rewrite_102101.patch
proxy_connect_rewrite_101504.patch  proxy_connect_rewrite.patch

github上開源了模塊 https://github.com/chobits/ngx_http_proxy_connect_module

此處用的是nginx-1.17.6,對應(yīng)proxy_connect_rewrite_1018.patch

配置nginx正向代理

下載后上傳到服務(wù)器

ls 
ngx_http_proxy_connect_module-master.zip    nginx-1.17.6.tar.gz

解壓nginx,解壓模塊并重命名

tar xf nginx-1.17.6.tar.gz
unzip ngx_http_proxy_connect_module-master.zip
mv ngx_http_proxy_connect_module-master ngx_http_proxy_connect_module
ls 
ngx_http_proxy_connect_module    nginx-1.17.6         ngx_http_proxy_connect_module-master.zip
nginx-1.17.6.tar.gz

安裝nginx

安裝源碼編譯工具包,nginx依賴包

yum -y install make gcc openssl openssl-devel pcre-devel zlib zlib-devel

進(jìn)入nginx解壓后的目錄

cd nginx-1.17.6 
./configure
make && make install

使用正向代理https的模塊

查看nginx-1.17.6對應(yīng)的https模塊的具體位置

ls /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch

導(dǎo)入模塊,再次編譯安裝

patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
./configure --add-module=/root/ngx_http_proxy_connect_module
 make && make install

配置正向代理

nginx默認(rèn)安裝在/usr/local/nginx/

 cd /usr/local/nginx/

修改配置文件

 vim conf/nginx.conf    

在 #gzip on; 下添加配置

 #正向代理轉(zhuǎn)發(fā)http請求
server {
    #指定DNS服務(wù)器IP地址
    resolver 114.114.114.114;
    #監(jiān)聽80端口,http默認(rèn)端口80
    listen 80;
    #服務(wù)器IP或域名
        server_name  localhost;
    #正向代理轉(zhuǎn)發(fā)http請求
    location / {
        proxy_pass                 http://$host$request_uri;
        proxy_set_header           HOST $host;
        proxy_buffers              256 4k;
        proxy_max_temp_file_size   0k;
        proxy_connect_timeout      30;
        proxy_send_timeout         60;
        proxy_read_timeout         60;
        proxy_next_upstream error  timeout invalid_header http_502;
    }
}
#正向代理轉(zhuǎn)發(fā)https請求
server {
    #指定DNS服務(wù)器IP地址
    resolver 114.114.114.114;
    #監(jiān)聽443端口,https默認(rèn)端口443
    listen 443;
   #正向代理轉(zhuǎn)發(fā)https請求
   proxy_connect;
   proxy_connect_allow            443 563;
   proxy_connect_connect_timeout  10s;
   proxy_connect_read_timeout     10s;
   proxy_connect_send_timeout     10s;
   location / {
        proxy_pass http://$host;
        proxy_set_header Host $host;
   }
}

檢查配置文件是否有錯誤sbin/nginx -t

創(chuàng)建nginx用戶,用來運(yùn)行nginx

useradd nginx

啟動服務(wù)

sbin/nginx

驗證正向代理

 curl -I http://www.baidu.com/ -v -x 127.0.0.1:80
 curl -I https://www.baidu.com/ -v -x 127.0.0.1:443

驗證正向代理http 200 ok

curl -I http://www.baidu.com/ -v -x 127.0.0.1:80
* About to connect() to proxy 127.0.0.1 port 80 (#0)
* ? Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> HEAD http://www.baidu.com/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx/1.17.6
Server: nginx/1.17.6
< Date: Sun, 28 Aug 2022 02:05:33 GMT
Date: Sun, 28 Aug 2022 02:05:33 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 277
Content-Length: 277
< Connection: keep-alive
Connection: keep-alive
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Etag: "575e1f7c-115"
Etag: "575e1f7c-115"
< Last-Modified: Mon, 13 Jun 2016 02:50:36 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:36 GMT
< Pragma: no-cache
Pragma: no-cache
<
* Connection #0 to host 127.0.0.1 left intact

驗證正向代理https 200 ok

curl -I https://www.baidu.com/ -v -x 127.0.0.1:443
* About to connect() to proxy 127.0.0.1 port 443 (#0)
* ? Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 443 (#0)
* Establish HTTP proxy tunnel to www.baidu.com:443
> CONNECT www.baidu.com:443 HTTP/1.1
> Host: www.baidu.com:443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection Established
HTTP/1.1 200 Connection Established
< Proxy-agent: nginx
Proxy-agent: nginx
<
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* ? CAfile: /etc/pki/tls/certs/ca-bundle.crt
? CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* ? ? ? subject: CN=baidu.com,O="Beijing Baidu Netcom Science Technology Co., Ltd",OU=service operation department,L=beijing,ST=beijing,C=CN
* ? ? ? start date: 7月 05 05:16:02 2022 GMT
* ? ? ? expire date: 8月 06 05:16:01 2023 GMT
* ? ? ? common name: baidu.com
* ? ? ? issuer: CN=GlobalSign RSA OV SSL CA 2018,O=GlobalSign nv-sa,C=BE
> HEAD / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Connection: keep-alive
Connection: keep-alive
< Content-Length: 277
Content-Length: 277
< Content-Type: text/html
Content-Type: text/html
< Date: Sun, 28 Aug 2022 02:05:50 GMT
Date: Sun, 28 Aug 2022 02:05:50 GMT
< Etag: "575e1f7c-115"
Etag: "575e1f7c-115"
< Last-Modified: Mon, 13 Jun 2016 02:50:36 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:36 GMT
< Pragma: no-cache
Pragma: no-cache
< Server: bfe/1.0.8.18
Server: bfe/1.0.8.18
<
* Connection #0 to host 127.0.0.1 left intact

到此這篇關(guān)于nginx正向代理http和https的實現(xiàn)步驟的文章就介紹到這了,更多相關(guān)nginx正向代理http和https內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • nginx反向代理失效前端無法獲取后端的數(shù)據(jù)解決辦法

    nginx反向代理失效前端無法獲取后端的數(shù)據(jù)解決辦法

    Nginx服務(wù)器的反向代理服務(wù)是其最常用的重要功能,由反向代理服務(wù)也可以衍生出很多與此相關(guān)的Nginx服務(wù)器重要功能,下面這篇文章主要給大家介紹了關(guān)于nginx反向代理失效前端無法獲取后端的數(shù)據(jù)解決的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • nginx之從main函數(shù)開始了解配置文件處理及配置信息的讀入過程

    nginx之從main函數(shù)開始了解配置文件處理及配置信息的讀入過程

    這篇文章主要介紹了nginx之從main函數(shù)開始了解配置文件處理及配置信息的讀入過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-07-07
  • Nginx?Proxy?Manager配置Web?WAF應(yīng)用防火墻

    Nginx?Proxy?Manager配置Web?WAF應(yīng)用防火墻

    Nginx?Proxy?Manager是一款功能強(qiáng)大的開源軟件,配置Web應(yīng)用防火墻,可以防止常見的web攻擊,本文就來介紹一下Nginx?Proxy?Manager配置Web?WAF應(yīng)用防火墻,感興趣的可以了解一下
    2025-02-02
  • Nginx?403?forbidden錯誤的五種原因及詳細(xì)解決方法

    Nginx?403?forbidden錯誤的五種原因及詳細(xì)解決方法

    這篇文章主要給大家介紹了關(guān)于Nginx?403?forbidden錯誤的五種原因及詳細(xì)解決方法,相信很多人對403 forbidden是什么意思有了大致的了解,那么當(dāng)我們遇到403 forbidden怎么解決呢,需要的朋友可以參考下
    2023-08-08
  • Nginx熱部署的實現(xiàn)

    Nginx熱部署的實現(xiàn)

    本文主要介紹了Nginx熱部署的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 從零實現(xiàn)Nginx風(fēng)格內(nèi)存池完整代碼

    從零實現(xiàn)Nginx風(fēng)格內(nèi)存池完整代碼

    本文將從為什么需要內(nèi)存池講起,重點探討內(nèi)存池的設(shè)計哲學(xué),并詳細(xì)拆解其實現(xiàn)方案,從而搭建起讀者對內(nèi)存池從理論到實踐的完整認(rèn)知模型,感興趣的朋友跟隨小編一起看看吧
    2026-05-05
  • ubuntu 下的nginx服務(wù)器配置詳解

    ubuntu 下的nginx服務(wù)器配置詳解

    這篇文章主要介紹了ubuntu 下的nginx服務(wù)器配置詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • lnmp環(huán)境中如何為nginx開啟pathinfo

    lnmp環(huán)境中如何為nginx開啟pathinfo

    這篇文章主要介紹了lnmp環(huán)境中如何為nginx開啟pathinfo的方法,操作很簡單,需要的朋友可以參考下
    2015-01-01
  • Nginx負(fù)載均衡之upstream模塊簡介與使用詳解

    Nginx負(fù)載均衡之upstream模塊簡介與使用詳解

    nginx有一個最大的功能就是可以實現(xiàn)服務(wù)器的負(fù)載均衡,下面這篇文章主要給大家介紹了關(guān)于Nginx負(fù)載均衡之upstream模塊簡介與使用的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • nginx轉(zhuǎn)載到多個服務(wù)器實例代碼

    nginx轉(zhuǎn)載到多個服務(wù)器實例代碼

    本文主要介紹了nginx轉(zhuǎn)載到多個服務(wù)器實例代碼,通過修改nginx.conf文件實現(xiàn)前端路由轉(zhuǎn)發(fā)和后端服務(wù)器實例添加,具有一定的參考價值,感興趣的可以了解一下
    2025-09-09

最新評論

鹤岗市| 昭平县| 抚州市| 靖州| 雅安市| 台北市| 万年县| 正宁县| 黔江区| 民丰县| 大余县| 齐河县| 自治县| 衡南县| 民权县| 东明县| 开化县| 江陵县| 灌云县| 新巴尔虎右旗| 永嘉县| 收藏| 河北区| 奇台县| 天津市| 错那县| 灵山县| 信宜市| 思茅市| 福鼎市| 济南市| 普安县| 磴口县| 郸城县| 渑池县| 太康县| 隆安县| 阜康市| 禹城市| 惠来县| 翼城县|