apache2 - 如何将子域映射到在端口 8086 上运行的 tomcat 8 Web 应用程序

标签 apache2 ubuntu-16.04 virtualhost tomcat8

我有一个子域 test.example.com。 我有一个 java Web 应用程序在端口 8086 上的 tomcat 8.5 中运行。

在/opt/tomcat/conf/server.xml 中,我定义了一个虚拟主机,如下所示。

<Host name="canicarry.thehatapps.com" appBase="webapps/SecondAmendmentSupporters-0.2" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="canicarry_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

我有一个 apache2 conf 定义,如下所示。 /etc/apache2/sites-available/test.example.com.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        ServerName test.example.com
        ServerAlias www.test.example.com.com
        DocumentRoot /var/www/test.example.com/public_html

        <Directory /var/www/test.example.com/public_html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

在 public_html 中,我定义了 .htaccess,如下所示。

RedirectPermanent / http://test.example.com:8086

我的目标是能够像这样 http://canicarry.thehatapps.com:8086 一样访问端口 8086 上的 myapp-02 tomcat Web 应用程序

我不确定出了什么问题,但我得到了 404。我似乎无法解决 http://canicarry.thehatapps.com:8086到我在 tomcat 中运行的网络应用程序。

如有任何帮助,我们将不胜感激。

已编辑------------ 在我的 apache conf 文件中使用它有所帮助,但仍然遇到问题。

<VirtualHost canicarry.thehatapps.com/*:80>
  ServerName canicarry.thehatapps.com
  ProxyRequests Off
  ProxyPass / ajp://localhost:8086/SecondAmendmentSupporters-0.2
  ProxyPassReverse / ajp://localhost:8086/SecondAmendmentSupporters-0.2
</VirtualHost>

当我输入http://canicarry.thehatapps.com:8086时,我被带到了

http://104.238.96.249:8086/SecondAmendmentSupporters-0.2/

这是我的 tomcat 应用程序的完整 URL。但是,当我附加端点时,它无法解析。另外,url应该还是http://canicarry.thehatapps.com:8086 。它不应显示 tomcat 应用程序实例的完整 url。

例如,http://canicarry.thehatapps.com:8086/places应该从服务返回地点列表,但它不会解析 URL。

最佳答案

您的<VirtualHost *:80>告诉 apache 监听端口 80

如果您希望应用程序通过端口 8086 公开那么你需要代理端口8086到你的 tomcat 服务器。您可以使用 ajp_proxy 来执行此操作apache的模块。

<VirtualHost test.example.com:8086>
  ServerName test.example.com
  ProxyRequests Off
  ProxyPass /examples ajp://127.0.0.1:8086/examples
  ProxyPassReverse /examples ajp://localhost:8086/examples
</VirtualHost>

详情请参阅下面的文章

https://linuxconfig.org/how-to-set-up-apache-webserver-proxy-in-front-of-apache-tomcat-on-red-hat-linux

关于apache2 - 如何将子域映射到在端口 8086 上运行的 tomcat 8 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56796515/

相关文章:

Apache:无效命令 'SSLEngine',可能拼写错误或由未包含在服务器配置中的模块定义

amazon-web-services - 遵循 Let's Encrypt 教程后 AWS Lightsail 上的 Server.crt 问题

java - 错误 : illegal character: '\ufeff' in java

php - 最近从 5.3 更新的 PHP 5.4 在使用变量等于条件快捷方式时崩溃

react-native - com.android.builder.testing.api.DeviceException : No connected devices

node.js - NPM 在 docker 容器中升级后中断

apache - Apache 2.4 中的 VirtualHost 在使用 http 时替换 DocumentRoot ://localhost

apache - 在我的 Apache Docker 容器中,如何设置代理来路由其他代理未处理的所有内容?

php - 休眠 php 进程 (mod_fcgid) 快速消耗 RAM

.htaccess - Web 服务器不读取 .htaccess 文件