Httpd服务入门知识-正向代理和反向代理

                                                作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.正向代理和反向代理

启用反向代理
  ProxyPass "/" "http://www.example.com/"
  ProxyPassReverse "/" "http://www.example.com/"

特定URL反向代理
  ProxyPass "/images" "http://www.example.com/"
  ProxyPassReverse "/images" http://www.example.com/

示例:
<VirtualHost *>
  ServerName www.yinzhengjie.org.cn
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
</VirtualHost>

二.反向代理配置实战

1>.试验节点角色分配

node101.yinzhengjie.org.cn
  客户端 node105.yinzhengjie.org.cn:
  提供"/"路径的服务 node106.yinzhengjie.org.cn:
  提供"/blog"路径的服务 node107.yinzhengjie.org.cn:
  反向代理服务器

2>.node105.yinzhengjie.org.cn节点配置

[root@node105.yinzhengjie.org.cn ~]# yum -y install httpd
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.jdcloud.com
* extras: mirror.jdcloud.com
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB ::
extras | 2.9 kB ::
updates | 2.9 kB ::
updates//x86_64/primary_db | 5.8 MB ::
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 :2.4.-.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.-.el7.centos for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libaprutil-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libapr-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 :1.4.-.el7 will be installed
---> Package apr-util.x86_64 :1.5.-.el7 will be installed
---> Package httpd-tools.x86_64 :2.4.-.el7.centos will be installed
--> Finished Dependency Resolution Dependencies Resolved =======================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================
Installing:
httpd x86_64 2.4.-.el7.centos base 2.7 M
Installing for dependencies:
apr x86_64 1.4.-.el7 base k
apr-util x86_64 1.5.-.el7 base k
httpd-tools x86_64 2.4.-.el7.centos base k Transaction Summary
=======================================================================================================================
Install Package (+ Dependent packages) Total download size: 3.0 M
Installed size: 9.9 M
Downloading packages:
(/): apr-util-1.5.-.el7.x86_64.rpm | kB ::
(/): apr-1.4.-.el7.x86_64.rpm | kB ::
(/): httpd-2.4.-.el7.centos.x86_64.rpm | 2.7 MB ::
(/): httpd-tools-2.4.-.el7.centos.x86_64.rpm | kB ::
-----------------------------------------------------------------------------------------------------------------------
Total kB/s | 3.0 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.-.el7.x86_64 /
Installing : apr-util-1.5.-.el7.x86_64 /
Installing : httpd-tools-2.4.-.el7.centos.x86_64 /
Installing : httpd-2.4.-.el7.centos.x86_64 /
Verifying : apr-1.4.-.el7.x86_64 /
Verifying : httpd-tools-2.4.-.el7.centos.x86_64 /
Verifying : apr-util-1.5.-.el7.x86_64 /
Verifying : httpd-2.4.-.el7.centos.x86_64 / Installed:
httpd.x86_64 :2.4.-.el7.centos Dependency Installed:
apr.x86_64 :1.4.-.el7 apr-util.x86_64 :1.5.-.el7 httpd-tools.x86_64 :2.4.-.el7.centos Complete!
[root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# yum -y install httpd

[root@node105.yinzhengjie.org.cn ~]# echo "<h1>node105.yinzhengjie.org.cn<h1>" > /var/www/html/index.html
[root@node105.yinzhengjie.org.cn ~]#
[root@node105.yinzhengjie.org.cn ~]# cat /var/www/html/index.html
<h1>node105.yinzhengjie.org.cn<h1>
[root@node105.yinzhengjie.org.cn ~]#
[root@node105.yinzhengjie.org.cn ~]# systemctl start httpd
[root@node105.yinzhengjie.org.cn ~]#
[root@node105.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node105.yinzhengjie.org.cn ~]#

3>.node106.yinzhengjie.org.cn节点配置

[root@node106.yinzhengjie.org.cn ~]# yum -y install httpd
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB ::
extras | 2.9 kB ::
updates | 2.9 kB ::
(/): base//x86_64/group_gz | kB ::
(/): extras//x86_64/primary_db | kB ::
(/): base//x86_64/primary_db | 6.0 MB ::
(/): updates//x86_64/primary_db | 5.8 MB ::
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 :2.4.-.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.-.el7.centos for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libaprutil-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libapr-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 :1.4.-.el7 will be installed
---> Package apr-util.x86_64 :1.5.-.el7 will be installed
---> Package httpd-tools.x86_64 :2.4.-.el7.centos will be installed
--> Finished Dependency Resolution Dependencies Resolved ===============================================================================================================
Package Arch Version Repository Size
===============================================================================================================
Installing:
httpd x86_64 2.4.-.el7.centos base 2.7 M
Installing for dependencies:
apr x86_64 1.4.-.el7 base k
apr-util x86_64 1.5.-.el7 base k
httpd-tools x86_64 2.4.-.el7.centos base k Transaction Summary
===============================================================================================================
Install Package (+ Dependent packages) Total download size: 3.0 M
Installed size: 9.9 M
Downloading packages:
(/): apr-util-1.5.-.el7.x86_64.rpm | kB ::
(/): apr-1.4.-.el7.x86_64.rpm | kB ::
(/): httpd-tools-2.4.-.el7.centos.x86_64.rpm | kB ::
(/): httpd-2.4.-.el7.centos.x86_64.rpm | 2.7 MB ::
---------------------------------------------------------------------------------------------------------------
Total 2.6 MB/s | 3.0 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.-.el7.x86_64 /
Installing : apr-util-1.5.-.el7.x86_64 /
Installing : httpd-tools-2.4.-.el7.centos.x86_64 /
Installing : httpd-2.4.-.el7.centos.x86_64 /
Verifying : apr-1.4.-.el7.x86_64 /
Verifying : httpd-tools-2.4.-.el7.centos.x86_64 /
Verifying : apr-util-1.5.-.el7.x86_64 /
Verifying : httpd-2.4.-.el7.centos.x86_64 / Installed:
httpd.x86_64 :2.4.-.el7.centos Dependency Installed:
apr.x86_64 :1.4.-.el7 apr-util.x86_64 :1.5.-.el7 httpd-tools.x86_64 :2.4.-.el7.centos Complete!
[root@node106.yinzhengjie.org.cn ~]#

[root@node106.yinzhengjie.org.cn ~]# yum -y install httpd

[root@node106.yinzhengjie.org.cn ~]# echo "<h1>https://www.cnblogs.com/yinzhengjie/</h1>" > /var/www/html/index.html
[root@node106.yinzhengjie.org.cn ~]#
[root@node106.yinzhengjie.org.cn ~]# cat /var/www/html/index.html
<h1>https://www.cnblogs.com/yinzhengjie/</h1>
[root@node106.yinzhengjie.org.cn ~]#
[root@node106.yinzhengjie.org.cn ~]# systemctl start httpd
[root@node106.yinzhengjie.org.cn ~]#
[root@node106.yinzhengjie.org.cn ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node106.yinzhengjie.org.cn ~]#
[root@node106.yinzhengjie.org.cn ~]#

4>.node107.yinzhengjie.org.cn节点配置

[root@node107.yizhengjie.org.cn ~]# yum -y install httpd
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.jdcloud.com
* extras: mirror.jdcloud.com
* updates: mirrors.aliyun.com
base | 3.6 kB ::
extras | 2.9 kB ::
updates | 2.9 kB ::
(/): base//x86_64/group_gz | kB ::
(/): extras//x86_64/primary_db | kB ::
(/): base//x86_64/primary_db | 6.0 MB ::
(/): updates//x86_64/primary_db | 5.8 MB ::
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 :2.4.-.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.-.el7.centos for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libaprutil-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Processing Dependency: libapr-.so.()(64bit) for package: httpd-2.4.-.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 :1.4.-.el7 will be installed
---> Package apr-util.x86_64 :1.5.-.el7 will be installed
---> Package httpd-tools.x86_64 :2.4.-.el7.centos will be installed
--> Finished Dependency Resolution Dependencies Resolved =============================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================
Installing:
httpd x86_64 2.4.-.el7.centos base 2.7 M
Installing for dependencies:
apr x86_64 1.4.-.el7 base k
apr-util x86_64 1.5.-.el7 base k
httpd-tools x86_64 2.4.-.el7.centos base k Transaction Summary
=============================================================================================================================================
Install Package (+ Dependent packages) Total download size: 3.0 M
Installed size: 9.9 M
Downloading packages:
(/): httpd-tools-2.4.-.el7.centos.x86_64.rpm | kB ::
(/): apr-1.4.-.el7.x86_64.rpm | kB ::
(/): apr-util-1.5.-.el7.x86_64.rpm | kB ::
httpd-2.4.-.el7.centos.x86_ FAILED ] 1.6 B/s | kB :: ETA
http://mirrors.nju.edu.cn/centos/7.7.1908/os/x86_64/Packages/httpd-2.4.6-90.el7.centos.x86_64.rpm: [Errno 12] Timeout on http://mirrors.nju.e
du.cn/centos/7.7./os/x86_64/Packages/httpd-2.4.-.el7.centos.x86_64.rpm: (, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.
(/): httpd-2.4.-.el7.centos.x86_64.rpm | 2.7 MB ::
---------------------------------------------------------------------------------------------------------------------------------------------
Total kB/s | 3.0 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.-.el7.x86_64 /
Installing : apr-util-1.5.-.el7.x86_64 /
Installing : httpd-tools-2.4.-.el7.centos.x86_64 /
Installing : httpd-2.4.-.el7.centos.x86_64 /
Verifying : apr-1.4.-.el7.x86_64 /
Verifying : httpd-tools-2.4.-.el7.centos.x86_64 /
Verifying : apr-util-1.5.-.el7.x86_64 /
Verifying : httpd-2.4.-.el7.centos.x86_64 / Installed:
httpd.x86_64 :2.4.-.el7.centos Dependency Installed:
apr.x86_64 :1.4.-.el7 apr-util.x86_64 :1.5.-.el7 httpd-tools.x86_64 :2.4.-.el7.centos Complete!
[root@node107.yizhengjie.org.cn ~]#

[root@node107.yizhengjie.org.cn ~]# yum -y install httpd

[root@node107.yizhengjie.org.cn ~]# cat /etc/httpd/conf.d/proxy.conf
#ProxyPass "/" "http://node105.yinzhengjie.org.cn/"              #此处我将配置注释掉了,此时无法访问node105.yinzhengjie.org.cn,但是可以访问node106.yinzhengjie.org.cn,想要同时启用则不行,还是推荐使用nginx或者haproxy来做反向代理吧。
#ProxyPassReverse "/" "http://node105.yinzhengjie.org.cn/" ProxyPass "/blog" "http://node106.yinzhengjie.org.cn/"
ProxyPassReverse "/blog" "http://node106.yinzhengjie.org.cn/"
[root@node107.yizhengjie.org.cn ~]#
[root@node107.yizhengjie.org.cn ~]# httpd -t
Syntax OK
[root@node107.yizhengjie.org.cn ~]#
[root@node107.yizhengjie.org.cn ~]# systemctl start httpd
[root@node107.yizhengjie.org.cn ~]#
[root@node107.yizhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node107.yizhengjie.org.cn ~]#
[root@node107.yizhengjie.org.cn ~]#

5>.客户端访问

[root@node101.yinzhengjie.org.cn ~]# curl http://node107.yinzhengjie.org.cn/blog
<h1>https://www.cnblogs.com/yinzhengjie/</h1>
[root@node101.yinzhengjie.org.cn ~]#

三.httpd服务的应用

  httpd主要应用在于web服务器,比如常见的lamp架构。

  httpd可以支持反向代理的功能,但和nginx,haproxy相比httpd显得有点逊色了。

  生产环境中httpd做反向代理的案例特别的少,因此不推荐大家使用httpd做反向代理,推荐使用专业的nginx或者haproxy来做反向代理。

Httpd服务入门知识-正向代理和反向代理的更多相关文章

  1. Httpd服务入门知识-Httpd服务安装

    Httpd服务入门知识-Httpd服务安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Httpd概述 1>.Httpd介绍 20世纪90年代初,国家超级计算机应用中心 ...

  2. Httpd服务入门知识-http协议版本,工作机制及http服务器应用扫盲篇

    Httpd服务入门知识-http协议版本,工作机制及http服务器应用扫盲篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Internet与中国 Internet最早来源于美 ...

  3. Httpd服务入门知识-https(http over ssl)安全配置

    Httpd服务入门知识-https(http over ssl)安全配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.SSL会话的简化过程 ()客户端发送可供选择的加密方式, ...

  4. Httpd服务入门知识-使用mod_deflate模块压缩页面优化传输速度

    Httpd服务入门知识-使用mod_deflate模块压缩页面优化传输速度 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.mod_deflate模块概述 mod_deflate ...

  5. Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机

    Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.虚拟主机实现方案 1>.Apache httpd 有三种实现虚 ...

  6. Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面

    Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.status功能概述 status页 ...

  7. Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项

    Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ServerSignature指令概述 ...

  8. Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享

    Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.实现用户家目录的http共享前提 在配置家目录共 ...

  9. Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名

    Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.创建测试数据 [root@node101.yinzhengj ...

随机推荐

  1. Codeforces Round 563 (Div. 2) 题解

    自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...

  2. 【BigData】Java基础_ArrayList的使用

    ArrayList概述 ArrayList底层使用的是数组.是List的可变数组实现,这里的可变是针对List而言,而不是底层数组. 数组有自身的特点,不变性,一旦数组被初始化,那么其长度就固定了,不 ...

  3. node.js HTTP模块、URL 模块

    在浏览器输入存在的网址的一个交互过程 1.用户通过浏览器发送一个http的请求到指定的主机 2.服务器接收到该请求,对该请求进行分析和处理 3.服务器处理完成以后,返回对应的数据到用户机器 4.浏览器 ...

  4. a标签设置水平右对齐

      1.情景展示 如上图所示,这其实是一个a标签,如何让它右对齐呢? 2.解决方案 第一步:将行内标签转化成块级元素,即display:block: 第二步:文字右对齐,即text-align:rig ...

  5. of_property_read_string_index(转)

    https://biscuitos.github.io/blog/DTS-of_property_read_string_index/ 源码分析 of_property_read_string_ind ...

  6. eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义

    问题:eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义 在使用getbean或者扫包时注入bean失败,但在IDE里是可以正常运行的? 原因:导出jar未 ...

  7. TP5配置隐藏入口index.php文件

    隐藏的index.php PS:这里说的入口文件指的是公共/ index.php文件,配置文件就在这个目录下 可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则 ...

  8. c++ 内存二进制表示

    int a=1 string b="1" 1.其中变量a在内存中的二进制是 0000 0001 2.那么变量b是一个字符串,ascii码是49(字符串1的ascii码是49)通过计 ...

  9. 微信小程序之使用函数防抖与函数节流

    函数防抖和函数节流都是老生常谈的问题了.这两种方式都能优化 js 的性能.有些人可能会搞混两个的概念.所以,我以自己的理解,来解释这两个概念的含义.并且列举在小程序中这两个方法的使用. 函数防抖: 英 ...

  10. git实战中遇到git@github.com: Permission denied (publickey).的问题

    一.问题我们在使用git的时候会建立一个私钥和一个公钥来完成彼此的通讯,因此如何使用给一个指令建立一个秘钥至关重要.但是我在实践的过程中出现了git@github.com: Permission de ...