【问题标题】:How to configure https for an apache redirecting to tomcat via mod_proxy connector (ajp)如何为通过 mod_proxy 连接器(ajp)重定向到 tomcat 的 apache 配置 https
【发布时间】:2017-04-26 10:16:49
【问题描述】:

我在 linux 系统(亚马逊 aws 上)上有一个 apache 服务器,使用 https 运行。我也有一个tomcat。我想使用 apache 作为 tomcat 的前门。我为 apache 启用了 mod_proxy 模块,并且重定向到 tomcat 工作正常,看起来像这样:

<VirtualHost *:80>
   ServerName my.domain.com

   #Log
   ErrorLog /var/log/ajp.error.log
   CustomLog /var/log/ajp.log combined

   #AJP configuration
   <Proxy *>
       Order deny,allow
       Deny from all
       Allow from all
   </Proxy>

   ProxyRequests Off

   ProxyPass / ajp://localhost:8009/
   ProxyPassReverse / ajp://localhost:8009/

 </VirtualHost>

我在 /etc/httpd/conf.d 文件夹中的文件 httpd.conf 的底部添加了这一行。

但是,如果我在 httpd.conf 文件中添加另一个 VirtualHost 以重定向到 https,则重定向到 https 有效,但将显示 apache 测试页面,而不是 tomcat 页面。如果我删除此重定向 VirtualHost,将显示 apache tomcat 页面。我还启用了 mod_rewrite 模块。我在 ssl.conf (/etc/httpd/conf.d/ssl.conf) 中配置的 https 东西,它工作正常。在那里我设置了 ssl 证书,如果客户端使用已知的 https 证书发出请求,服务器将回答该请求。否则不会。

我添加到 httpd.conf 的 https 重定向的 VirtualHost 如下所示:

    <VirtualHost *:80>
         ServerName my.domain.com
         RewriteEngine on
         ReWriteCond %{SERVER_PORT} !^443$
         RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
    </VirtualHost>

你能帮帮我吗?我在这里做错了什么?我应该在 /etc/httpd/conf.d/ssl.conf 文件中进行更改吗?我很

【问题讨论】:

    标签: apache tomcat https mod-proxy ajp


    【解决方案1】:

    好的,现在我找到了解决该问题的方法。在 VirtualHost 结束之前,我在 /etc/httpd/conf.d/ssl.conf 的底部写了这行:

    #Log
    ErrorLog /var/log/ajp.error.log
    CustomLog /var/log/ajp.log combined
    
    #AJP configuration
    <Proxy *>
           Order deny,allow
           Deny from all
           Allow from all
    </Proxy>
    
    ProxyRequests Off
    
    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    

    【讨论】:

      【解决方案2】:

      下面的块

      <VirtualHost *:80>
        ServerName my.domain.com
        # [...]
      </VirtualHost>
      

      就像是说“这个块将为http://my.domain.com 处理一切”。您不能添加具有相同端口/服务器名称的另一个:它们不会合并,一个会影响另一个。

      如果 https 部分已经工作并且您想将所有 http 流量重定向到 https,您可以完全注释/删除第一个 &lt;VirtualHost *:80&gt; 块(使用代理)。 &lt;VirtualHost *:443&gt; 中的代理规则将处理所有事情(假设 https 部分有效)。

      如果您只想将部分重定向到 https(不是您的问题,但这应该可以帮助您理解它),您应该将 RewriteEngine / ReWriteCond / RewriteRule 指令放在里面现有的虚拟主机。

      【讨论】:

      • 感谢您的回答。现在我删除了第二个 VirtualHost,并将第一个带有 ajp 和代理的 Virtual Host 更改为 。我重定向到 https,但它不指向 tomcat 页面。我看到了 apache 测试页面。我还尝试在第一个中添加第二个 VirtualHost 的重写规则,但行为是相同的。我看到的是 apache 测试页,而不是 tomcat 起始页。我该如何处理?我做错了什么?
      猜你喜欢
      • 2013-05-27
      • 2011-03-24
      • 2016-07-04
      • 2010-10-31
      • 2012-11-01
      • 2015-07-09
      • 2017-05-08
      • 2020-12-09
      • 2012-05-07
      相关资源
      最近更新 更多