Как сопоставить поддомен с веб-приложением tomcat 8, работающим на порте 8086 - PullRequest
5 голосов
/ 27 июня 2019

У меня есть поддомен test.example.com. У меня есть веб-приложение Java, работающее в Tomcat 8.5 на порт 8086.

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

Моя цель - иметь возможность подключиться к веб-приложению myapp-02 tomcat через порт 8086 примерно так: http://canicarry.thehatapps.com:8086

Я не уверен, что не так, но я получаю 404. Кажется, я не могу разрешить http://canicarry.thehatapps.com:8086 моему веб-приложению, запущенному в tomcat.

Буду признателен за любую помощь.

EDITED ----------- Использование этого в моем файле 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/

Какой полный URL-адрес моего приложения tomcat. Однако, когда я добавляю конечную точку, она не разрешается. Кроме того, URL-адрес по-прежнему должен быть http://canicarry.thehatapps.com:8086.. Он не должен отображать полный URL-адрес экземпляра приложения tomcat.

Например, http://canicarry.thehatapps.com:8086/places должен возвращать список мест из сервиса, но он не разрешает URL.

1 Ответ

1 голос
/ 08 июля 2019

Ваш <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

...