- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
Nginx 正向代理是一种常用的网络代理服务,它允许内部网络中的客户端通过代理服务器访问外部网络(如互联网)上的资源。
以下是一个基础的配置示例,展示了如何设置Nginx以实现HTTP正向代理功能。
1、安装nginx
1.1 系统命令安装
apt install nginx #ubantu系统
yum install nginx #centos系统
1.2 docker 安装
# 下载后解压
tar -xf docker-20.10.0.tgz
cp docker/* /usr/local/bin/
cat > /etc/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://www.landui.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
# 重新加载 daemon 用于启动 docker
systemctl daemon-reload
# 重新启动 docker 刷新出 /etc/docker 目录
systemctl restart docker
1.3 启动nginx容器
docke run -d --name nginx --network host -v /root/nginx/nginx:/etc/nginx/conf.d nginx
1.4 配置nginx
注意:/etc/nginx/nginx.conf文件中http模块增加include /etc/nginx/conf.d/*.conf;
vi /etc/nginx/conf.d/nginx.conf
server {
resolver 114.114.114.114; #指定DNS服务器IP地址
listen 8082;
location / {
proxy_pass http://$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;
}
}
nginx -t #检查nginx 配置
nginx -s reload #重新加载nginx
2、目标机器配置代理
仅支持http正向代理
vi /etc/profile
export http_proxy='http://www.landui.com:8082'
source /etc/profile
3、目标机器测试
curl -vv http://www.landui.com
请注意,如果需要支持HTTPS正向代理,还需额外的配置,因为默认情况下Nginx可能不允许CONNECT方法,这是HTTPS隧道所需的。蓝队云官网上拥有完善的技术支持库可供参考,大家可自行查阅,更多技术问题,可以直接咨询。同时,蓝队云整理了运维必备的工具包免费分享给大家使用,需要的朋友可以直接咨询。更多技术知识,蓝队云期待与你一起探索。
售前咨询
售后咨询
备案咨询
二维码
TOP