【问题标题】:reverse proxy for multiple websites多个网站的反向代理
【发布时间】:2018-11-09 16:30:08
【问题描述】:

最初,我在我的网络上安装了两个 Weblogic 应用程序服务器,第一个 WebLogic 的 IP 地址为 192.168.0.201(主机名 firstserver.example.com) 和 IP 地址 192.168.0.202 上的第二个 Weblogic 服务器(主机名 secondserver.example.com) 我已经在我的 oracle 虚拟机上安装了 apache 服务器(配置反向代理以进行测试)

最初,我为一台应用服务器配置了反向代理 我已经像这样配置了反向代理 httpd.conf

<VirtualHost 127.0.0.1:80>
    ServerName www.firstserver.com
     ServerAlias firstserver.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
    ProxyPass  http://firstserver.example.com:7001/console/ retry=0
    ProxyPassReverse   http://firstserver.example.com:7001/console/
   
     </Location>
</VirtualHost>

当我在浏览器(www.firstserver.com/console/)上输入以下地址时,它运行良好。

我在主机文件中输入了以下详细信息

    192.168.0.201 firstserver.example.com   firstserver
    192.168.0.202 secondserver.example.com   secondserver
当我尝试反向代理两个应用程序服务器时

我尝试过在 httpd.conf 中使用不同的设置,例如

Listen 192.168.0.201:80
Listen 192.168.0.202:80
NameVirtualHost 192.168.0.201:80
NameVirtualHost 192.168.0.202:80
<VirtualHost 192.168.0.201:80>
    ServerName www.firstserver.com
     ServerAlias firstserver.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
    ProxyPass  http://firstserver.example.com:7001/console/ retry=0
    ProxyPassReverse   http://firstserver.example.com:7001/console/
    
   
     </Location>
</VirtualHost>
<VirtualHost 192.168.0.202:80>
    ServerName www.secondserver.com
     ServerAlias secondserver.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
    ProxyPass  http://secondserver.com:7001/console/ retry=0
    ProxyPassReverse   http://secondserver.com:7001/console/
    
   
     </Location>
</VirtualHost>

但是没有用 请建议我更好的解决方案

【问题讨论】:

  • 1- 如果您使用的是 Apache 2.4,则不再有 NameVirtualHost 的名称。 2-拆分您的日志文件,以便您可以知道来自一个虚拟主机和另一个虚拟主机的内容。 3-你有任何日志吗?将您的 LogLevel 进行跟踪。 4-您确定可以从代理连接到端口 7001 上的两台服务器吗? 5-您的主机文件的名称中有 ...example...,但您没有在 Apache 配置中使用它。

标签: apache weblogic reverse-proxy virtualhost httpd.conf


【解决方案1】:

您的 apache 配置表明您误解了“Listen”和“Servername”指令的含义。这些应该是解析到网络服务器的值,告诉 Apache 在哪个 IP 地址上侦听请求以及如何处理到达“www.webserver.com”的任何 HTTP 请求。这些不应该以任何方式解析到应用程序服务器。

如果您将“[网络服务器的 IP 地址] www.webserver.com”添加到运行浏览器的机器的主机文件中,此示例将适用于您的示例:

    <VirtualHost *:80>
     ServerName www.webserver.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
         ProxyPass  http://firstserver:7001/console/ 
         ProxyPassReverse   http://firstserver:7001/console/
     </Location>

这是一个 NamedVirtualHost 示例,说明您是否会在 客户端上为您的网络服务器提供第二个主机文件条目(“www.webserver2.com”):

   <VirtualHost *:80>
     ServerName www.webserver.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
         ProxyPass  http://firstserver:7001/console/ 
         ProxyPassReverse   http://firstserver:7001/console/
     </Location>
   </VirtualHost>

    <VirtualHost *:80>
     ServerName www.webserver2.com
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log

     <Location /console/>
         ProxyPass  http://secondserver:7001/console/ 
         ProxyPassReverse   http://secondserver:7001/console/
     </Location>
   </VirtualHost>

这样,您可以从客户端访问 www.webserver.com/console 和 www.webserver2.com/console

【讨论】:

  • 但我想在这种情况下为多个应用程序服务器(第一台服务器,第二台服务器)使用多个虚拟主机我们如何编辑 httpd.conf 文件
  • 我添加了一个扩展示例,该示例基于更多 DNS 名称解析到浏览器客户端 PC 上的网络服务器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
  • 2019-09-12
相关资源
最近更新 更多