用nginx做正向代理,即(使内网机器可以通过互联网服务器上互联网
创始人
2025-01-19 19:32:08
0

用nginx做正向代理,即(使内网机器可以通过互联网服务器上互联网)

  • 1.下载nginx安装包 此处下载nginx-1.20
  • 2.下载正向代理模块包
  • 3.部署nginx服务
    • 3.1. 上传nginx包和正向模块包至互联网服务器
    • 3.2 解压 改名
    • 3.3 安装nginx
    • 3.4 配置正向代理(举例,将正向代理端口配置在8030上)
    • 3.5 测试nginx所在的互联网机器是否正常
    • 3.6 内网机器全局配置,所有请求都能够正常使用代理访问外网
    • 3.7测试内网服务器(即不能访问外网的服务器),使用代理上网

1.下载nginx安装包 此处下载nginx-1.20

https://nginx.org/en/download.html 官网下载地址

2.下载正向代理模块包

https://github.com/chobits/ngx_http_proxy_connect_module 下载地址

nginx版本与代理模块对照表
在这里插入图片描述

3.部署nginx服务

此处使用的是nginx-1.20.2,对应proxy_connect_rewrite_1018.patch

3.1. 上传nginx包和正向模块包至互联网服务器

3.2 解压 改名

tar -xf nginx.tar.gz unzip ngx_http_proxy_connect_module-master.zip mv ngx_http_proxy_connect_module-master ngx_http_proxy_connect_module 

3.3 安装nginx

基础运行环境安装

yum -y install make gcc openssl openssl-devel pcre-devel zlib zlib-devel 

查看正向代理模块proxy_connect_rewrite_1018.patch的位置

ll ../ngx_http_proxy_connect_module/patch/ 

导入模块 后面为模块路径

patch -p1 < /nginx/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch 

编译

#配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态 ./configure --add-module=/nginx/ngx_http_proxy_connect_module --prefix=/usr/local/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module 

安装nginx 安装位置根据 编译时配置的–prefix=

make && make install 

3.4 配置正向代理(举例,将正向代理端口配置在8030上)

在nginx.conf文件里的http节点下增加

server {     listen 8030;     server_name localhost;     resolver 114.114.114.114 ipv6=off;     proxy_connect;                                    proxy_connect_allow            all;     proxy_connect_connect_timeout  10s;     proxy_connect_read_timeout     10s;     proxy_connect_send_timeout     10s;          location / {         proxy_pass https://$host$request_uri;         proxy_set_header HOST $host;         proxy_http_version  1.1;         proxy_ssl_server_name on;     } } 

3.5 测试nginx所在的互联网机器是否正常

 curl -I http://www.baidu.com/ -v -x 127.0.0.1:8030  curl -I https://www.baidu.com/ -v -x 127.0.0.1:8030   HTTP/1.1 200 Connection Established Proxy-agent: nginx  HTTP/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 

3.6 内网机器全局配置,所有请求都能够正常使用代理访问外网

# 追加配置 vim /etc/profile # 这里的地址要写代理的服务器地址 http_proxy=192.168.0.20:80 # 这里的地址要写代理的服务器地址 https_proxy=192.168.0.20:443 # 这里的地址要写代理的服务器地址 ftp_proxy=192.168.0.20:443 export http_proxy export https_proxy export ftp_proxy # 加载配置 source /etc/profile 

3.7测试内网服务器(即不能访问外网的服务器),使用代理上网

curl -I https://www.baidu.com -v -x http://ip:8030  HTTP/1.1 200 Connection Established Proxy-agent: nginx  HTTP/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 

此时内网机器已经可以通过互联网机器对应的正向代理端口访问互联网了

相关内容

热门资讯

2026版总结!aa poke... 2026版总结!aa poker透视软件(透视)hhpoker透视方法-总是是有挂(哔哩哔哩)1、a...
来临!小程序微乐辅助器2.0免... 来临!小程序微乐辅助器2.0免费,微乐小程序免费黑科技,练习教程(有挂工具)-哔哩哔哩1、金币登录送...
透视科技!wpk私人局有透视吗... 透视科技!wpk私人局有透视吗(透视)wpk私人辅助-一贯真的有挂(哔哩哔哩)1、该软件可以轻松地帮...
透视辅助!微乐小程序黑科技,微... 透视辅助!微乐小程序黑科技,微乐小程序黑科技,指南教程(有挂软件)-哔哩哔哩一、微乐小程序黑科技游戏...
为切实保障!微乐小程序黑科技免... 为切实保障!微乐小程序黑科技免费知乎,微乐小程序黑科技,手筋教程(有挂工具)-哔哩哔哩1、微乐小程序...
现有关情况通报如下!wpk透视... 现有关情况通报如下!wpk透视辅助靠谱吗(透视)wpk免费辅助-原来是有挂(哔哩哔哩)1、wpk透视...
2026版教程!智星德州有脚本... 2026版教程!智星德州有脚本吗(透视)智星德州插件-真是真的有挂(哔哩哔哩)1.智星德州有脚本吗 ...
透视线上!微乐小程序免费脚本,... 透视线上!微乐小程序免费脚本,微乐小程序免费黑科技,指南书教程(有挂神器)-哔哩哔哩1、游戏颠覆性的...
透视代打!aapoker脚本怎... 透视代打!aapoker脚本怎么用(透视)hhpoker软件靠谱吗-原来存在有挂(哔哩哔哩)一、aa...
出现新变化!微乐房间辅助工具在... 出现新变化!微乐房间辅助工具在哪下载,微乐小程序黑科技,法门教程(有挂app)-哔哩哔哩1、微乐房间...