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

时间:2019-06-27 18:03:44

标签: apache2 ubuntu-16.04 virtualhost tomcat8

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

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

Default

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

<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>

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

<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>

我的目标是像这样http://canicarry.thehatapps.com:8086

能够在端口8086上访问myapp-02 tomcat Web应用程序

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

任何帮助将不胜感激。

编辑----------- 在我的apache conf文件中使用此功能虽然有帮助,但仍然遇到问题。

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

当我输入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应该从服务中返回一个地点列表,但是它不能解析网址。

1 个答案:

答案 0 :(得分:1)

您的/^\d{0,2}(\.\d{1,2})?$/.test() 告诉apache监听端口<VirtualHost *:80>

如果您希望应用程序通过端口80公开,则需要将端口8086代理到您的tomcat服务器。您可以使用apache的8086模块来完成此操作。

ajp_proxy

有关详情,请参见下面的文章

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