Centos上配置两层nginx转发,把请求转发到外网
【机器】
内网机器A(10.1.125.10):运行python程序。
内网机器B(10.1.131.20):内网nginx代理。
外网机器C(10.1.148.30):外网nginx代理。
【目标】
在机器A上配置pip源,把外网请求mirrors.aliyun.com通过两层nginxB和C转发到外网。
【步骤】
1、在机器A上,修改pip配置,使用aliyun的镜像。
mkdir /root/.pip
vi /root/.pip/pip.conf
[global] index-url=http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com
2、在机器A上,修改 /etc/hosts 文件,加入如下一行:
10.1.131.20 mirrors.aliyun.com #指向机器B的nginx
3、在机器B上,修改 /etc/hosts 文件,加入如下一行:
10.1.148.30 mirrors.aliyun.com #指向机器C的nginx
4、在机器B上,配置nginx,增加如下配置:
server { listen 80; server_name mirrors.aliyun.com; location / { proxy_pass http://mirrors.aliyun.com; } }
5、在机器C上,配置nginx,增加如下配置:
server { listen 80; server_name mirrors.aliyun.com; location / { proxy_pass http://mirrors.aliyun.com; } }
到这里就配置完了,执行pip命令时,实际是请求http://mirrors.aliyun.com/pypi/simple地址,请求先从A转发到B,再从B转发到C,在从C转发到外网,最终返回结果。
作者:Lave Zhang
出处:http://www.cnblogs.com/lavezhang/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步