局域网机器配置Nginx正向代理访问外网服务

正向代理

1 简介

2 请求逻辑

+-----------------+ +-----------------+ +-----------------+ | 内网集群客户端 | | Nginx代理服务器 | | 外网目标服务器 | +-----------------+ +-----------------+ +-----------------+ | | | | | | | 1. 发送HTTP请求 |------->| 2. 接收HTTP请求 |------->| 3. 处理HTTP请求 | | |<-------| |<-------| | | 4. 接收HTTP响应 | | 5. 发送HTTP响应 | | 6. 返回HTTP响应 | | | | | | | +-----------------+ +-----------------+ +-----------------+

3. 搭建使用

正向代理配置nginx.conf

step1.首先准备好一个正向代理配置文件nginx.conf,放到某个位置,如:/data/xiaoming/nginx/nginx.conf

#user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server { listen 8888; resolver 8.8.8.8; proxy_connect; proxy_connect_allow 443 563; proxy_connect_connect_timeout 90s; proxy_connect_read_timeout 90s; proxy_connect_send_timeout 90s; location / { proxy_pass http://$host; proxy_set_header Host $host; } } }

step2. 在有外网环境的机器启动Nginx,例如IP是10.21.190.11

docker run --name nginx -itd -v /data/xiaoming/nginx/nginx.conf:/etc/nginx/nginx.conf -p 8888:8888 zzc932/nginx:https_proxy

在内网集群设置代理

export http_proxy=http://10.21.190.11:8888 export https_proxy=http://10.21.190.11:8888

验证

curl www.baidu.com apt-get update 或 yum update

__EOF__

本文作者钟子期
本文链接https://www.cnblogs.com/nishiliu/p/17266378.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   钟子期  阅读(1272)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示