配置nginx反向代理

在之前nginx, php ,mariadb 的基础上配置反向代理
之前的配置链接
https://blog.csdn.net/weixin_38232096/article/details/124557082

克隆快照,创建两个新系统
web 代理服务器 222.111.106.11;
server1 222.111.106.12;
server2 222.111.106.13;

  1. Nginx反向代理后端http网站
    分别重新安装httpd, php
    yum -y install httpd php
    [root@sunny2 ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/webhtml"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/webhtml">

[root@sunny2 ~]# cat /var/www/webhtml/index.php
This is www2
在这里插入图片描述
[root@sunny2 ~]# vim /var/www/webhtml/index.php
在这里插入图片描述

下面在主服务器配置代理
[root@sunny ~]# vim /usr/local/nginx/conf/nginx.conf

    upstream cluster1 {
         server 222.111.106.12;
         server 222.111.106.13;
    }


    location / {
        root   html;
        index  index.php index.html;
        **proxy_pass http://cluster1;**
     }

重启nginx
#ngx-reload

Ctrl+F5 刷新页面
在这里插入图片描述
在这里插入图片描述
2. Nginx 反向代理后端ssh服务器
配置nginx.conf
[root@sunny ~]# vim /usr/local/nginx/conf/nginx.conf

stream {
    upstream ssh_node2{
      server 222.111.106.17:22 max_fails=3 fail_timeout=30s;
}

    server {
     listen 2222;
     proxy_connect_timeout 60s;
     proxy_timeout 10m;
     proxy_pass ssh_node2;

  }

}

测试:

[root@sunny ~]# netstat -tnl|grep 2222
tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN  

在另外一台电脑测试,通过代理服务器访问

Connection to 222.111.106.18 closed.
[root@sunny2 ~]# ssh -p 2222  root@222.111.106.18
root@222.111.106.18's password: 
Last login: Thu May  5 15:45:36 2022 from 222.111.106.18
[root@sunny2 ~]# 

在这里插入代码片
[root@sunny2 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 222.111.106.17  netmask 255.255.0.0  broadcast 222.111.255.255
        inet6 fe80::a143:dcb9:e70f:b133  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::80e1:a1cc:ff67:ab7c  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::eaa:1060:4b26:40f6  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ec:58:39  txqueuelen 1000  (Ethernet)
        RX packets 490525  bytes 37520797 (35.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4145  bytes 837842 (818.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值