提问者:小点点

如何配置https的apache重定向到tomcat通过mod_proxy连接器(ajp)


我在linux系统上有一个apache服务器(在amazon aws上),使用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>

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

但是如果我在httpd. conf文件中添加另一个VirtualHost以重定向到https,重定向到https是有效的,但是会显示apache Test页面,而不是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文件中进行更改吗?我很


共2个答案

匿名用户

好的,现在我得到了这个问题的解决方案。在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/

匿名用户

以下块

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

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

如果https部分已经工作并且您想将所有超文本传输协议流量重定向到https,您可以完全注释/删除第一个

如果您只想将部分重定向到https(不是您的问题,但这应该有助于您理解它),您应该将Rewrite eEngine/ReWriteCond/Rewrite eLaw指令放入现有的虚拟主机中。