文章目录
一、正向代理图
结构图
主机 | 是否可以访问外网 | 安装 |
---|---|---|
192.168.1.10 | 不可以 | 配置http_proxy和https_proxy,指向192.168.1.20 |
192.168.1.20 | 可以 | 安装nginx |
目标
让局域网内无法访问网络的服务器,依靠局域网内一台可以访问网络的服务器访问网络。
包括http、https、docker pull等
二、注意事项
1、官网下载的nginx 只支持http,不支持https
2、要支持https,需要把nginx重新编译
相关地址
1、nginx的下载地址
wget http://nginx.org/download/nginx-1.9.12.tar.gz
2、编译依赖的下载地址
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
3、优秀的参考文档
https://blog.csdn.net/Arthashit/article/details/96694552
https://www.cnblogs.com/chenjinxi/p/13265877.html
三、快速使用
该快速使用是直接使用docker直接进行部署的。
3.1 在可以访问网络的服务器,比如案例中的 192.168.1.20
启动docker
docker pull registry.cn-hangzhou.aliyuncs.com/chencanzhan/centos7-nginx-https:v2.0
docker run -itd -p外网端口:8765 --name=nginx-proxy registry.cn-hangzhou.aliyuncs.com/chencanzhan/centos7-nginx-https:v2.0
例如:
docker run -itd -p4321:8765 --name=nginx-proxy registry.cn-hangzhou.aliyuncs.com/chencanzhan/centos7-nginx-https:v2.0
3.2 在不可以联网的服务器,比如案例中的 192.168.1.10
设置 http proxy
百度无法访问了
[root@master ~]# curl www.baidu.com
curl: (6) Could not resolve host: www.baidu.com; 未知的错误
export http_proxy=http://192.168.1.20:4321
百度可以访问了
[root@master ~]# curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value
设置 https proxy
github无法访问
[root@master ~]# curl https://github.com
curl: (6) Could not resolve host: github.com; 未知的错误
export https_proxy=http://192.168.1.20:4321
github可以访问了
[root@master ~]# curl https://github.com
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<link rel="dns-prefetch" href="https://github.githubassets.com">
<link rel="dns-prefetch" href="https://avatars.githubusercontent.com">
<link rel="dns-prefetch" href="https://github-cloud.s3.amazonaws.com">
<link rel="dns-prefetch" href="https://user-images.githubusercontent.com/">
<link rel="preconnect" href="https://github.githubassets.com" crossorigin>
<link rel="preconnect" href="https://avatars.githubusercontent.com">
docker的代理配置
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.1.20:4321"
vim /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]
Environment="HTTPS_PROXY=http://192.168.1.20:4321"
systemctl daemon-reload
systemctl restart docker
systemctl show --property=Environment docker (验证)