在之前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;
- 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
|