反向代理:反向代理服务器架设在服务器端,通过缓冲经常被请求的页面来缓解服务器的工作量,将客户机请求转发给内部网络上的目标服务器;并将从服务器上得到的结果返回给Internet
上请求连接的客户端,此时代理服务器与目标主机一起对外表现为一个服务器。
1. 环境准备:
主机名 | 网卡配置 |
node1 | 外网网卡:ens33 外网地址:192.168.188.11 网卡模式:NAT模式 内网网卡:ens37 外网地址:192.168.255.137 网卡模式:仅主机模式 |
node2 | 网卡名称:ens33 网卡地址:192.168.255.138 网卡网关:192.168.255.137 网卡模式:仅主机模式 |
node3 | 客户端 |
2. 内网服务器配置:
[root@node2 ~]# echo "this is page" > /var/www/html/index.html
[root@node2 ~]# systemctl start httpd
3. 代理服务器配置:
## 配置扩展源
[root@node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com
/repo/epel-7.repo
## 安装Nginx
[root@node1 ~]# yum install -y nginx
##配置反向代理:
[root@node1 ~]# vim /etc/nginx/nginx.conf
...
location / {
proxy_pass http://192.168.255.138; ## 访问后端服务器地址
}
...
## 重启Nginx
[root@node1 ~]# systemctl restart nginx.service
4. 通过客户端访问代理服务器外网:
[root@node3 ~]# curl 192.168.188.11
this is page