ngxin 正向代理配置 访问互联网

如果本地无法访问互联网,则通过nginx的正向代理,可以将本地的所有流量进行代理,从而达到访问互联网的目的,话不多说,上代码:

1、下载nginx并安装相关依赖

复制代码
yum -y install gcc
yum install -y gcc-c++ 
yum install -y pcre pcre-devel 
yum install -y zlib zlib-devel 
yum install -y openssl openssl-devel
mkdir -p /mnt/soft/installPackage
cd /mnt/soft/installPackage
wget http://nginx.org/download/nginx-1.18.0.tar.gz

2、解压nginx压缩包

复制代码
tar -zxvf nginx-1.18.0.tar.gz

3、下载正向代理插件,此插件为必须

复制代码
yum install git
yum -y install patch
git clone https://gitee.com/web_design_of_web_frontend/ngx_http_proxy_connect_module.git

4、编译正向代理插件

复制代码
cd /mnt/soft/installPackage/nginx-1.18.0
patch -p1 < /mnt/soft/installPackage/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch

5、编译安装nginx

复制代码
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/mnt/soft/installPackage/ngx_http_proxy_connect_module
make && make install

安装目录:/usr/local/nginx

配置文件目录:/usr/local/nginx/conf/nginx.conf

6、配置正向代理

复制代码
server {
     listen 9090;
     resolver 114.114.114.114 valid=60s ipv6=off;
     resolver_timeout 30s;
     proxy_connect;
     proxy_connect_allow            443 80;
     proxy_connect_connect_timeout  10s;
     proxy_connect_read_timeout     10s;
     proxy_connect_send_timeout     10s;
     location / {
         proxy_pass $scheme://$http_host$request_uri;
         proxy_set_header Host $host;
         proxy_http_version  1.1;
         #proxy_ssl_server_name on;
     }
}

7、启动nginx

复制代码
cd /usr/local/nginx/sbin
./nginx
或
/usr/local/nginx/sbin/ngxin

8、开机自启动

复制代码
cd /usr/lib/systemd/system/
vi nginx.service
#复制以下内容到nginx.service文件中[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

9、重启nginx,加入开机自启动

复制代码
pkill -9 nginx
systemctl start nginx
systemctl enable nginx

10、配置系统代理

11、打开浏览器,访问外网地址,可以正常打开了

相关推荐
一水鉴天2 小时前
整体设计 定稿 之9 最后收束 app.py: 应用项目的结构及其模型和框架 (豆包助手)
服务器·windows·microsoft
wanhengidc2 小时前
云手机的适配性怎么样?
运维·服务器·安全·智能手机·云计算
梁辰兴2 小时前
计算机网络基础:使用集线器的星型拓扑
服务器·网络·计算机网络·集线器·计算机网络基础·梁辰兴·星型拓扑
jimy12 小时前
安卓里运行Linux
linux·运维·服务器
咕噜签名-铁蛋3 小时前
PyTorch:深度学习框架的创新之路与技术实践
服务器
哟哟耶耶3 小时前
js-fetch流式实现中断重连
运维·服务器
爱凤的小光3 小时前
Linux清理磁盘技巧---个人笔记
linux·运维
TG:@yunlaoda360 云老大4 小时前
如何在华为云国际站代理商控制台进行SFS Turbo的性能与容量核查?
服务器·网络·数据库·华为云
耗同学一米八4 小时前
2026年河北省职业院校技能大赛中职组“网络建设与运维”赛项答案解析 1.系统安装
linux·服务器·centos
知星小度S5 小时前
系统核心解析:深入文件系统底层机制——Ext系列探秘:从磁盘结构到挂载链接的全链路解析
linux