网站建设 自适应,怎么做百度推广,wordpress娱乐网,哈尔版网站建设nginx正向代理的配置和使用 nginx正向代理的配置和使用nginx正向代理的配置和使用安装包准备下载nginx安装包下载正向代理模块的包版本与模块对照表部署nginx服务上传nginx包和正向模块包解压,改名安装nginx配置正向代理创建nginx用户检查nginx配置并启动nginx服务所在服务器验…nginx正向代理的配置和使用 nginx正向代理的配置和使用nginx正向代理的配置和使用安装包准备下载nginx安装包下载正向代理模块的包版本与模块对照表部署nginx服务上传nginx包和正向模块包解压,改名安装nginx配置正向代理创建nginx用户检查nginx配置并启动nginx服务所在服务器验证正向代理功能配置不能访问外网的服务器即内网服务器,使其可以访问外网liunx服务器配置1.只配置使用yum时能够使用正向代理访问外网2.只配置使用wget时能够使用正向代理访问外网3.全局配置所以访问请求都能够使用正向代理访问外网windows服务器配置验证不能访问外网的服务器即内网服务器,使用代理上网nginx正向代理httpnginx正向代理https 正向代理指的是通过代理服务器 代理浏览器/客户端去重定向请求访问到目标服务器 的一种代理服务。正向代理服务的特点是代理服务器 代理的对象是浏览器/客户端也就是对于目标服务器 来说浏览器/客户端是隐藏的。 nginx默认支持正向代理http不支持https nginx官方并不支持直接转发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包和正向模块包
[rootmysql 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 -zcf /root/nginx.tar.gz
unzip ngx_http_proxy_connect_module-master.zipll
drwxr-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.gz
drwxr-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_modulell
drwxr-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.gz
drwxr-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.ru
drwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 conf
-rwxr-xr-x 1 1001 1001 2590 Nov 16 2021 configure
drwxr-xr-x 4 1001 1001 4096 Feb 12 15:20 contrib
drwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 html
-rw-r--r-- 1 1001 1001 1397 Nov 16 2021 LICENSE
drwxr-xr-x 2 1001 1001 4096 Feb 12 15:20 man
-rw-r--r-- 1 1001 1001 49 Nov 16 2021 README
drwxr-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# 查看nginx
ll /usr/local/nginx/
drwx------ 2 nobody root 4096 Feb 12 15:47 client_body_temp
drwxr-xr-x 2 root root 4096 Feb 12 15:46 conf
drwx------ 2 nobody root 4096 Feb 12 15:47 fastcgi_temp
drwxr-xr-x 2 root root 4096 Feb 12 15:28 html
drwxr-xr-x 2 root root 4096 Feb 12 15:47 logs
drwx------ 2 nobody root 4096 Feb 12 15:47 proxy_temp
drwxr-xr-x 2 root root 4096 Feb 12 15:33 sbin
drwx------ 2 nobody root 4096 Feb 12 15:47 scgi_temp
drwx------ 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 -t
sbin/nginxss -utnlp | grep nginx
tcp LISTEN 0 511 *:443 *:* users:((nginx,pid6645,fd7),(nginx,pid6644,fd7))
tcp LISTEN 0 511 *:80 *:* users:((nginx,pid6645,fd6),(nginx,pid6644,fd6))nginx服务所在服务器验证正向代理功能 curl -I http://www.baidu.com/ -v -x 127.0.0.1:80curl -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.1User-Agent: curl/7.29.0Host: www.baidu.comAccept: */*Proxy-Connection: Keep-AliveHTTP/1.1 200 OK
HTTP/1.1 200 OKServer: nginx/1.20.2
Server: nginx/1.20.2Date: Sun, 12 Feb 2023 09:03:40 GMT
Date: Sun, 12 Feb 2023 09:03:40 GMTContent-Type: text/html
Content-Type: text/htmlContent-Length: 277
Content-Length: 277Connection: keep-alive
Connection: keep-aliveAccept-Ranges: bytes
Accept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transformEtag: 575e1f60-115
Etag: 575e1f60-115Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTPragma: no-cache
Pragma: 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:443CONNECT www.baidu.com:443 HTTP/1.1Host: www.baidu.com:443User-Agent: curl/7.29.0Proxy-Connection: Keep-AliveHTTP/1.1 200 Connection Established
HTTP/1.1 200 Connection EstablishedProxy-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.crtCApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CNbaidu.com,OBeijing Baidu Netcom Science Technology Co., Ltd,OUservice operation department,Lbeijing,STbeijing,CCN
* start date: Jul 05 05:16:02 2022 GMT
* expire date: Aug 06 05:16:01 2023 GMT
* common name: baidu.com
* issuer: CNGlobalSign RSA OV SSL CA 2018,OGlobalSign nv-sa,CBEHEAD / HTTP/1.1User-Agent: curl/7.29.0Host: www.baidu.comAccept: */*HTTP/1.1 200 OK
HTTP/1.1 200 OKAccept-Ranges: bytes
Accept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transformConnection: keep-alive
Connection: keep-aliveContent-Length: 277
Content-Length: 277Content-Type: text/html
Content-Type: text/htmlDate: Sun, 12 Feb 2023 09:03:40 GMT
Date: Sun, 12 Feb 2023 09:03:40 GMTEtag: 575e1f60-115
Etag: 575e1f60-115Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMTPragma: no-cache
Pragma: no-cacheServer: bfe/1.0.8.18
Server: bfe/1.0.8.18
* Connection #0 to host 127.0.0.1 left intact配置不能访问外网的服务器即内网服务器,使其可以访问外网
liunx服务器配置
1.只配置使用yum时能够使用正向代理访问外网
#追加配置
vim /etc/yum.conf
proxyhttp://192.168.0.20:80 #nginx正向代理服务器的地址
proxyftp://192.168.0.20:80 #nginx正向代理服务器的地址2.只配置使用wget时能够使用正向代理访问外网
#追加配置
vim /etc/wgetrc
http_proxy192.168.0.20:80 #nginx正向代理服务器的地址
http_proxy192.168.0.20:443 #nginx正向代理服务器的地址3.全局配置所以访问请求都能够使用正向代理访问外网
#追加配置
vim /etc/profile
http_proxy192.168.0.20:80
https_proxy192.168.0.20:443
ftp_proxy192.168.0.20:443export http_proxy
export https_proxy
export ftp_proxy# 加载配置
source /etc/profilewindows服务器配置 验证不能访问外网的服务器即内网服务器,使用代理上网
curl -I http://www.baidu.com
curl -I https://www.baidu.comcurl -I http://www.baidu.com
HTTP/1.1 200 OK
Server: nginx/1.20.2
Date: Sun, 12 Feb 2023 09:31:03 GMT
Content-Type: text/html
Content-Length: 277
Connection: keep-alive
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Etag: 575e1f60-115
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cachecurl -I https://www.baidu.com
HTTP/1.1 200 Connection Established
Proxy-agent: nginxHTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 12 Feb 2023 09:31:07 GMT
Etag: 575e1f60-115
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
文章转载自: http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.rbktw.cn.gov.cn.rbktw.cn http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn http://www.morning.jjpk.cn.gov.cn.jjpk.cn http://www.morning.iqcge.com.gov.cn.iqcge.com http://www.morning.lqlfj.cn.gov.cn.lqlfj.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.cwqrj.cn.gov.cn.cwqrj.cn http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn http://www.morning.tmfm.cn.gov.cn.tmfm.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.qcnk.cn.gov.cn.qcnk.cn http://www.morning.gmztd.cn.gov.cn.gmztd.cn http://www.morning.npmpn.cn.gov.cn.npmpn.cn http://www.morning.ndfwh.cn.gov.cn.ndfwh.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.tpnxr.cn.gov.cn.tpnxr.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.sxjmz.cn.gov.cn.sxjmz.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.bmhc.cn.gov.cn.bmhc.cn http://www.morning.pmdzd.cn.gov.cn.pmdzd.cn http://www.morning.msmtf.cn.gov.cn.msmtf.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.horihe.com.gov.cn.horihe.com http://www.morning.sdecsd.cn.gov.cn.sdecsd.cn http://www.morning.xfhms.cn.gov.cn.xfhms.cn http://www.morning.tdwjj.cn.gov.cn.tdwjj.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.fhhry.cn.gov.cn.fhhry.cn http://www.morning.gl-group.cn.gov.cn.gl-group.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.ndxss.cn.gov.cn.ndxss.cn http://www.morning.ptzf.cn.gov.cn.ptzf.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.thzwj.cn.gov.cn.thzwj.cn http://www.morning.ubpsa.cn.gov.cn.ubpsa.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.crkhd.cn.gov.cn.crkhd.cn http://www.morning.wlggr.cn.gov.cn.wlggr.cn http://www.morning.nkqxb.cn.gov.cn.nkqxb.cn http://www.morning.uytae.cn.gov.cn.uytae.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.rglp.cn.gov.cn.rglp.cn http://www.morning.fldsb.cn.gov.cn.fldsb.cn http://www.morning.rpkl.cn.gov.cn.rpkl.cn http://www.morning.tlpsd.cn.gov.cn.tlpsd.cn http://www.morning.xrwbc.cn.gov.cn.xrwbc.cn http://www.morning.tbqbd.cn.gov.cn.tbqbd.cn http://www.morning.guangda11.cn.gov.cn.guangda11.cn http://www.morning.mlfgx.cn.gov.cn.mlfgx.cn http://www.morning.bpmdh.cn.gov.cn.bpmdh.cn http://www.morning.nclps.cn.gov.cn.nclps.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.gjlst.cn.gov.cn.gjlst.cn http://www.morning.rnlx.cn.gov.cn.rnlx.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.wqpb.cn.gov.cn.wqpb.cn http://www.morning.hrtfz.cn.gov.cn.hrtfz.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.pccqr.cn.gov.cn.pccqr.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.xrhst.cn.gov.cn.xrhst.cn http://www.morning.xltdh.cn.gov.cn.xltdh.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.fqklt.cn.gov.cn.fqklt.cn http://www.morning.qsfys.cn.gov.cn.qsfys.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.rlbg.cn.gov.cn.rlbg.cn http://www.morning.kwdfn.cn.gov.cn.kwdfn.cn http://www.morning.yrpd.cn.gov.cn.yrpd.cn