启用mod_proxy模块来配置转发代理。 m前端
# 模块默认已经启动web
[root@client ~]# grep "mod_proxy" /etc/httpd/conf.modules.d/00-proxy.conf vim
[root@client ~]# vim /etc/httpd/conf.d/f_proxy.conf后端
# 编辑一个新文件浏览器
<IfModule mod_proxy.c>服务器
# forward proxy function ON负载均衡
ProxyRequests Onide
<Proxy *>网站
# access permissionui
Require ip 127.0.0.1 10.0.0.0/24
</Proxy>
</IfModule>
[root@client ~]# vi /etc/httpd/conf/httpd.conf
# line 42: 增长监听端口
Listen 8080
[root@client ~]# systemctl restart httpd
启用mod_proxy模块来配置反向代理。环境以下:
(1) www.example.com [192.168.96.100] - Web Server#1
(2) web01.example.com [192.168.96.200] - Web Server#2
这个实验的目标是发送给www.example.com的请求被转发给web01.example.com.注意在完成本实验前,将上一个实验的转发代理请求关闭,不然本实验没法进行。
# 模块默认被启动
[root@server ~]# grep "mod_proxy" /etc/httpd/conf.modules.d/00-proxy.conf
[root@server ~]# vim /etc/httpd/conf.d/r_proxy.conf
# 建立一个新文件
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Require all granted
</Proxy>
# backend server and forwarded path
ProxyPass / http://web01.example.com/
ProxyPa***everse / http://web01.example.com/
</IfModule>
[root@server ~]# systemctl restart httpd
在客户端上访问前端服务器能够看到由后端服务器响应的请求。
(1) www.example.com [192.168.96.100] - Web Server#1
(2) web01.example.com [192.168.96.200] - Web Server#2
(3) web02.example.com [192.168.96.201] - Web Server#3
发送给前端www.example.com的请求会被转发给两台后端服务器。
[root@server ~]# vi /etc/httpd/conf.d/r_proxy.conf
# 从新配置该文件
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Require all granted
</Proxy>
# specify the way of load balancing with "lbmethod". it's also possible to set "bytraffic".
ProxyPass / balancer://cluster lbmethod=byrequests
<proxy balancer://cluster>
BalancerMember http://web01.example.com/ loadfactor=1
BalancerMember http://web02.example.com/ loadfactor=1
</proxy>
</IfModule>
[root@server ~]# systemctl restart httpd
在客户端上访问前端服务器,能够发现两台后端服务器的变化。