国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

nginx正向代理的配置和使用教程

瀏覽:3日期:2023-07-30 20:02:21
目錄安裝包準備下載nginx安裝包下載正向代理模塊的包版本與模塊對照表部署nginx服務上傳nginx包和正向模塊包配置正向代理創建nginx用戶檢查nginx配置并啟動nginx服務所在服務器驗證正向代理功能配置不能訪問外網的服務器(即內網服務器),使其可以訪問外網liunx服務器配置windows服務器配置驗證不能訪問外網的服務器(即內網服務器),使用代理上網

nginx正向代理http,nginx正向代理https

正向代理,指的是通過代理服務器 代理瀏覽器/客戶端去重定向請求訪問到目標服務器 的一種代理服務。正向代理服務的特點是代理服務器 代理的對象是瀏覽器/客戶端,也就是對于目標服務器 來說瀏覽器/客戶端是隱藏的。nginx默認支持正向代理http,不支持httpsnginx官方并不支持直接轉發https請求,nginx支持https需要ngx_http_proxy_connect_module模塊。github上開源了模塊 https://github.com/chobits/ngx_http_proxy_connect_module。不過維護的ngx_http_proxy_connect_module模塊的補丁也是有nginx版本限制的,需根據自身使用的nginx版本選擇相應的正向代理模塊。可以在REDEME.md的Select patch中查看nginx版本和模塊的對應關系安裝包準備下載nginx安裝包

下載地址

下載正向代理模塊的包

下載地址

版本與模塊對照表

部署nginx服務

此處使用的是nginx-1.20.2,對應proxy_connect_rewrite_1018.patch

上傳nginx包和正向模塊包mkdir /nginxcd /nginx[root@mysql nginx]# ll-rw-r--r-- 1 root root 1062124 Feb 12 15:23 nginx-1.20.2.tar.gz-rw-r--r-- 1 root root 57926 Feb 12 15:23 ngx_http_proxy_connect_module-master.zip

解壓,改名

tar -xf nginx.tar.gzunzip ngx_http_proxy_connect_module-master.ziplldrwxr-xr-x 9 1001 1001 4096 Feb 12 15:27 nginx-1.20.2-rw-r--r-- 1 root root 1062124 Feb 12 15:23 nginx-1.20.2.tar.gzdrwxr-xr-x 5 root root 4096 Feb 9 16:54 ngx_http_proxy_connect_module-master-rw-r--r-- 1 root root 57926 Feb 12 15:23 ngx_http_proxy_connect_module-master.zipmv ngx_http_proxy_connect_module-master ngx_http_proxy_connect_modulelldrwxr-xr-x 9 1001 1001 4096 Feb 12 15:27 nginx-1.20.2-rw-r--r-- 1 root root 1062124 Feb 12 15:23 nginx-1.20.2.tar.gzdrwxr-xr-x 5 root root 4096 Feb 9 16:54 ngx_http_proxy_connect_module-rw-r--r-- 1 root root 57926 Feb 12 15:23 ngx_http_proxy_connect_module-master.zip

安裝nginx

yum -y install make gcc openssl openssl-devel pcre-devel zlib zlib-develcd nginx-1.20.2ll drwxr-xr-x 6 1001 1001 4096 Feb 12 15:20 auto-rw-r--r-- 1 1001 1001 312251 Nov 16 2021 CHANGES-rw-r--r-- 1 1001 1001 476577 Nov 16 2021 CHANGES.rudrwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 conf-rwxr-xr-x 1 1001 1001 2590 Nov 16 2021 configuredrwxr-xr-x 4 1001 1001 4096 Feb 12 15:20 contribdrwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 html-rw-r--r-- 1 1001 1001 1397 Nov 16 2021 LICENSEdrwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 man-rw-r--r-- 1 1001 1001 49 Nov 16 2021 READMEdrwxr-xr-x 9 1001 1001 4096 Feb 12 15:20 src# 查看正向代理模塊proxy_connect_rewrite_1018.patch的位置ll ../ngx_http_proxy_connect_module/patch/-rw-r--r-- 1 root root 9849 Feb 9 16:54 proxy_connect_1014.patch-rw-r--r-- 1 root root 9697 Feb 9 16:54 proxy_connect.patch-rw-r--r-- 1 root root 9408 Feb 9 16:54 proxy_connect_rewrite_1014.patch-rw-r--r-- 1 root root 9505 Feb 9 16:54 proxy_connect_rewrite_101504.patch-rw-r--r-- 1 root root 9496 Feb 9 16:54 proxy_connect_rewrite_1015.patch-rw-r--r-- 1 root root 9553 Feb 9 16:54 proxy_connect_rewrite_1018.patch-rw-r--r-- 1 root root 9306 Feb 9 16:54 proxy_connect_rewrite_102101.patch-rw-r--r-- 1 root root 9337 Feb 9 16:54 proxy_connect_rewrite.patch# 導入模塊 后面為模塊路徑patch -p1 < /nginx/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch# 編譯./configure --add-module=/nginx/ngx_http_proxy_connect_module# 安裝,默認安裝在/usr/local/nginx/make && make install# 查看nginxll /usr/local/nginx/drwx------ 2 nobody root 4096 Feb 12 15:47 client_body_tempdrwxr-xr-x 2 root root 4096 Feb 12 15:46 confdrwx------ 2 nobody root 4096 Feb 12 15:47 fastcgi_tempdrwxr-xr-x 2 root root 4096 Feb 12 15:28 htmldrwxr-xr-x 2 root root 4096 Feb 12 15:47 logsdrwx------ 2 nobody root 4096 Feb 12 15:47 proxy_tempdrwxr-xr-x 2 root root 4096 Feb 12 15:33 sbindrwx------ 2 nobody root 4096 Feb 12 15:47 scgi_tempdrwx------ 2 nobody root 4096 Feb 12 15:47 uwsgi_temp配置正向代理cd /usr/local/nginx/#gzip on;下添加vim conf/nginx.conf #gzip on; #正向代理轉發http請求 server { #指定DNS服務器IP地址resolver 114.114.114.114; #監聽80端口,http默認端口80listen 80; #服務器IP或域名 server_name localhost; #正向代理轉發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; } } #正向代理轉發https請求 server {#指定DNS服務器IP地址 resolver 114.114.114.114;#監聽443端口,https默認端口443listen 443;#正向代理轉發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; } }創建nginx用戶

nginx服務以用戶nginx身份啟動

useradd nginx檢查nginx配置并啟動sbin/nginx -tsbin/nginxss -utnlp | grep nginxtcp LISTEN 0 511 *:443 *:* users:(('nginx',pid=6645,fd=7),('nginx',pid=6644,fd=7))tcp LISTEN 0 511 *:80 *:* users:(('nginx',pid=6645,fd=6),('nginx',pid=6644,fd=6))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:443curl -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 OKHTTP/1.1 200 OK< Server: nginx/1.20.2Server: nginx/1.20.2< Date: Sun, 12 Feb 2023 09:03:40 GMTDate: Sun, 12 Feb 2023 09:03:40 GMT< Content-Type: text/htmlContent-Type: text/html< Content-Length: 277Content-Length: 277< Connection: keep-aliveConnection: keep-alive< Accept-Ranges: bytesAccept-Ranges: bytes< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transformCache-Control: private, no-cache, no-store, proxy-revalidate, no-transform< Etag: '575e1f60-115'Etag: '575e1f60-115'< Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTLast-Modified: Mon, 13 Jun 2016 02:50:08 GMT< Pragma: no-cachePragma: no-cache<* Connection #0 to host 127.0.0.1 left intactcurl -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 EstablishedHTTP/1.1 200 Connection Established< Proxy-agent: nginxProxy-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: Jul 05 05:16:02 2022 GMT* expire date: Aug 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 OKHTTP/1.1 200 OK< Accept-Ranges: bytesAccept-Ranges: bytes< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transformCache-Control: private, no-cache, no-store, proxy-revalidate, no-transform< Connection: keep-aliveConnection: keep-alive< Content-Length: 277Content-Length: 277< Content-Type: text/htmlContent-Type: text/html< Date: Sun, 12 Feb 2023 09:03:40 GMTDate: Sun, 12 Feb 2023 09:03:40 GMT< Etag: '575e1f60-115'Etag: '575e1f60-115'< Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTLast-Modified: Mon, 13 Jun 2016 02:50:08 GMT< Pragma: no-cachePragma: no-cache< Server: bfe/1.0.8.18Server: bfe/1.0.8.18<* Connection #0 to host 127.0.0.1 left intact配置不能訪問外網的服務器(即內網服務器),使其可以訪問外網liunx服務器配置

1.只配置使用yum時,能夠使用正向代理訪問外網

#追加配置vim /etc/yum.confproxy=http://192.168.0.20:80#nginx正向代理服務器的地址proxy=ftp://192.168.0.20:80#nginx正向代理服務器的地址

2.只配置使用wget時,能夠使用正向代理訪問外網

#追加配置vim /etc/wgetrchttp_proxy=192.168.0.20:80 #nginx正向代理服務器的地址http_proxy=192.168.0.20:443 #nginx正向代理服務器的地址

3.全局配置,所以訪問請求都能夠使用正向代理訪問外網

#追加配置vim /etc/profilehttp_proxy=192.168.0.20:80https_proxy=192.168.0.20:443ftp_proxy=192.168.0.20:443export http_proxyexport https_proxyexport ftp_proxy# 加載配置source /etc/profilewindows服務器配置

驗證不能訪問外網的服務器(即內網服務器),使用代理上網curl -I http://www.baidu.comcurl -I https://www.baidu.comcurl -I http://www.baidu.comHTTP/1.1 200 OKServer: nginx/1.20.2Date: Sun, 12 Feb 2023 09:31:03 GMTContent-Type: text/htmlContent-Length: 277Connection: keep-aliveAccept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transformEtag: '575e1f60-115'Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTPragma: no-cachecurl -I https://www.baidu.comHTTP/1.1 200 Connection EstablishedProxy-agent: nginxHTTP/1.1 200 OKAccept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transformConnection: keep-aliveContent-Length: 277Content-Type: text/htmlDate: Sun, 12 Feb 2023 09:31:07 GMTEtag: '575e1f60-115'Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTPragma: no-cacheServer: bfe/1.0.8.18

到此這篇關于nginx正向代理的配置和使用教程的文章就介紹到這了,更多相關nginx正向代理內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Nginx
相關文章:
主站蜘蛛池模板: 亚洲理论欧美理论在线观看 | 老师张开腿让我爽了一夜视频 | 日本视频三区 | 在线观看精品国内福利视频 | 久久一级片 | 免费在线黄色网址 | 经典香港一级a毛片免费看 精品400部自拍视频在线播放 | 美女个护士一级毛片亚洲 | 欧美a级完整在线观看 | 国产香蕉影视院 | 日韩欧美色综合 | 女人张开腿让男人捅视频 | 中国日本高清免费视频网 | 亚洲精品一区二区三区五区 | 精品欧美一区二区三区精品久久 | 一本三道a无线码一区v小说 | 香港三级日本三级三级人妇 | 日韩欧美~中文字幕 | 久久精品国产这里是免费 | 国产欧美日韩视频在线观看 | 久草免费在线播放 | 三级网站视频 | 久久免费精彩视频 | 亚洲一级理论片 | 欧美国产综合日韩一区二区 | 精品国产一区二区三区在线 | 成年人免费观看的视频 | 精品三级国产一区二区三区四区 | 欧美激情一区二区亚洲专区 | 午夜爽爽视频 | 欧美午夜视频在线 | 三级黄色片日韩 | 久在线播放 | 深夜福利成人 | 二区中文字幕 | 亚洲综色 | 成人做爰网站免费看 | 亚洲精品亚洲人成在线麻豆 | 国产一区二区精品久久91 | 国产精品揄拍一区二区 | 杨幂国产精品福利在线观看 |