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、打开浏览器,访问外网地址,可以正常打开了

相关推荐
likfishdn10 分钟前
Linux的文件与目录管理
linux·运维·服务器
渲染101专业云渲染12 分钟前
川翔云电脑优势总结
服务器·3d·电脑·blender·maya
chian-ocean30 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=32 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
橘子味的茶二41 分钟前
高级系统架构师--第十章:计算机网络
服务器·计算机网络·系统架构
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
紫菜(Nori)1 小时前
短连接服务器压测-wrk
服务器·压力测试
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos