linux nginx配置代理_nginx四层负载均衡

linux nginx配置代理_nginx四层负载均衡3.2下载正向代理模块(这个模块可能不适合其他版本nginx)如果下载失败可用百度云:链接:提取码:下载解压nginxPS:编译,除正向代理模块外,其他看自己需求安装PS:3.4nginx.conf配置正向代理3.5启动nginx检查配置文件启动、停止、重载命令查看端口四、验证4.1202上面配置正向代理4.2对比202和203分别访问https和http##########################################

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

一、正向代理俗称VPN,图示如下:

在这里插入图片描述

二、实验机器

在这里插入图片描述

三、安装nginx 环境

3.1安装依赖

yum -y install pcre-devel zlib-devel gcc gcc+c++ make openssl-devel pcre-devel  zlib-devel patch

3.2 下载正向代理模块(这个模块可能不适合其他版本nginx)

mkdir -p /nginx-proxy
cd /nginx-proxy
wget https://github.com/chobits/ngx_http_proxy_connect_module/archive/refs/heads/master.zip
unzip ngx_http_proxy_connect_module-master.zip

如果下载失败可用百度云:
链接:https://pan.baidu.com/s/1tN1qsdsvXqIDX3jYkzWriA
提取码:q885

3.3安装nginx,并安装正向代理模块

下载解压nginx

cd /nginx-proxy
wget https://nginx.org/download/nginx-1.20.1.tar.gz
tar --no-same-owner -zxvf  nginx-1.20.1.tar.gz

PS:一定要先进入nginx 解压目录,再执行patch命令

cd /nginx-proxy/nginx-1.20.1
patch -p1 < /nginx-proxy/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_101504.patch

在这里插入图片描述

编译,除正向代理模块外,其他看自己需求安装
PS:/usr/local/nginx默认安装目录

cd /nginx-proxy/nginx-1.20.1
./configure --prefix=/usr/local/nginx   \
--with-http_ssl_module  --with-http_flv_module \
--with-http_stub_status_module --with-http_gzip_static_module \
--with-pcre  --add-module=/nginx-proxy/ngx_http_proxy_connect_module-master
make && make install

3.4 nginx.conf 配置正向代理

cd /usr/local/nginx/conf/
vim nginx.conf
worker_processes  auto;
events { 
   
    worker_connections  1024;
}
http { 
   
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    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;
############################################################
   # 配置http正向代理
   server { 
   
        resolver 8.8.8.8;      #指定DNS服务器IP地址
        listen 8000;
        server_name  localhost;
        location / { 
   
                proxy_pass http://$host$request_uri;     #设定代理服务器
    }
}
############################################################
   # 配置https正向代理
   server { 
   
        resolver 8.8.8.8;       #指定DNS服务器IP地址
        listen 4430;
        server_name  localhost;
        location / { 
   
                proxy_pass https://$host$request_uri;    #设定代理服务器的协议和地址
    }
}
############################################################
   server { 
   

        error_page   500 502 503 504  /50x.html;
        location = /50x.html { 
   
            root   html;
        }
    }
}

3.5 启动nginx

检查配置文件

/usr/local/nginx/sbin/nginx -t

启动、停止、重载命令

/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s reload

查看端口

[root@node1 conf]# netstat -lanp | grep 8000
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      14634/nginx: master
[root@node1 conf]# netstat -lanp | grep 4430
tcp        0      0 0.0.0.0:4430            0.0.0.0:*               LISTEN      14634/nginx: master

四、验证

4.1 202 上面配置正向代理

echo  "export http_proxy=192.168.199.201:8000" >>/etc/profile
echo  "export https_proxy=192.168.199.201:4430" >>/etc/profile
source /etc/profile

4.2 对比 202 和 203 分别访问 https 和http

###########################################
https 结果如下
###########################################

202上,可以看出解析IP为代理机192.168.199.201,测试成功

curl -I https://cn.bing.com/?mkt=zh-cn -v

在这里插入图片描述
203上,解析IP为本机公网IP
在这里插入图片描述
###########################################
http 也是成功的,就不贴了
###########################################

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/184321.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 冰蝎下的反弹shell连接msfconsole

    冰蝎下的反弹shell连接msfconsole文章目录前言一、使用木马getshell1.搭建环境二、冰蝎配置三、kali监听总结前言好久没碰美少妇(MSF)了,恰巧昨天在群里水群,有个表哥问为什么msf监听不到数据。为此我带着表哥的疑问进行了简单的研究。大体的流程和思路我简单记录一下。其中的坑还是不少的,希望这篇文章对初识冰蝎的表哥们有点用处。一、使用木马getshell冰蝎之所以强还是在于他的动态二进制加密。这里呢,在冰蝎下载的包中给出了官方的webshell。在server文件夹下。这里呢,我踩过一个坑。不知道是我电脑配置的问题还是就

    2025年9月26日
    3
  • 6个DIY移动APP开发平台「建议收藏」

    6个DIY移动APP开发平台「建议收藏」

    2022年5月31日
    32
  • 技巧 | json中文字符串中文乱码问题[通俗易懂]

    技巧 | json中文字符串中文乱码问题

    2022年2月13日
    44
  • postfix邮箱_用post方式发送文件

    postfix邮箱_用post方式发送文件一、首先关闭防火墙[root@localhost~]#systemctlstopfirewalld[root@localhost~]#setenforce0[root@localhost~]#getenforcePermissive二、搭建postfix[root@localhost~]#yuminstallpostfix三、配置postfix[root@local…

    2022年9月23日
    3
  • Autoencoder自动编码器的发展

    Autoencoder自动编码器的发展Autoencoder自动编码器的发展0、玻尔兹曼机中的测试实验——编码问题(1985)0.1、玻尔兹曼机0.2、受限的玻尔兹曼机0.3、编码问题——自动编码器雏形1、反向传播中的仿真——单层自动编码器(1986)2、利用神经网络进行数据降维——深度自动编码器(2006)3、去噪自编码器(2008)4、稀疏自编码器(2011)5、卷积自编码器(2011)6、变分自编码器(2013)6.1、模型6….

    2022年5月1日
    49
  • Vue2 后台管理系统解决方案

    Vue2 后台管理系统解决方案

    2021年10月11日
    39

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号