I have a webapp hosted on tomcat.
我在tomcat上托管了一个webapp。
Whenever I want to acess the app I have to use :8080 following my URL
每当我想访问我必须使用的应用程序:8080跟随我的URL
(eg: webapp.mydomain.com:8080).
I can't change the port on which Tomcat is listening to 80 because I need Apache to listen it.
我无法更改Tomcat正在侦听的端口80,因为我需要Apache来监听它。
Is there any way that allow me to acess my app using simple url webapp.mydomain.com ?
有没有办法让我使用简单的网址webapp.mydomain.com来访问我的应用程序?
2 个解决方案
#1
One easy option is to add a VirtualServer
with a ProxyPass
rule to your Apache configuration (either httpd.conf
, or a different config file in $APACHE_HOME/conf.d
).
一个简单的选择是将具有ProxyPass规则的VirtualServer添加到Apache配置(httpd.conf或$ APACHE_HOME / conf.d中的其他配置文件)。
This will tell Apache
to listen to requests on a specific domain, and forward those requests that match the domain onto a different host / port.
这将告诉Apache监听特定域上的请求,并将那些与域匹配的请求转发到不同的主机/端口。
Here's an example which will forward all requests to that domain (denoted by /) and send to a local Tomcat
running on port 8080
. I've also added logging example so you can check it working:
这是一个将所有请求转发到该域(用/表示)并发送到在端口8080上运行的本地Tomcat的示例。我还添加了日志示例,以便您可以检查它是否正常工作:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName webapp.mydomain.com
ServerAlias webapp
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog /var/log/httpd/webapp_error.log
CustomLog /var/log/httpd/webapp_access.log combined
CustomLog /var/log/httpd/webapp.log simple
</VirtualHost>
Apache VirtualHost docs: http://httpd.apache.org/docs/2.2/vhosts/
Apache VirtualHost文档:http://httpd.apache.org/docs/2.2/vhosts/
This needs the mod_proxy Apache
module. It might be installed already.
这需要mod_proxy Apache模块。它可能已经安装。
#2
You should configure Tomcat with Apache using AJP Connector/mod_jk(the Tomcat redirector module).
您应该使用AJP Connector / mod_jk(Tomcat重定向器模块)将Apache配置为Apache。
There are many articles if you google :
如果你谷歌有很多文章:
- Apache Tomcat Connector - Webserver HowTo
- Tomcat and Apache Setup
- Integrating Tomcat and Apache
Apache Tomcat Connector - Webserver HowTo
Tomcat和Apache安装程序
集成Tomcat和Apache
#1
One easy option is to add a VirtualServer
with a ProxyPass
rule to your Apache configuration (either httpd.conf
, or a different config file in $APACHE_HOME/conf.d
).
一个简单的选择是将具有ProxyPass规则的VirtualServer添加到Apache配置(httpd.conf或$ APACHE_HOME / conf.d中的其他配置文件)。
This will tell Apache
to listen to requests on a specific domain, and forward those requests that match the domain onto a different host / port.
这将告诉Apache监听特定域上的请求,并将那些与域匹配的请求转发到不同的主机/端口。
Here's an example which will forward all requests to that domain (denoted by /) and send to a local Tomcat
running on port 8080
. I've also added logging example so you can check it working:
这是一个将所有请求转发到该域(用/表示)并发送到在端口8080上运行的本地Tomcat的示例。我还添加了日志示例,以便您可以检查它是否正常工作:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName webapp.mydomain.com
ServerAlias webapp
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog /var/log/httpd/webapp_error.log
CustomLog /var/log/httpd/webapp_access.log combined
CustomLog /var/log/httpd/webapp.log simple
</VirtualHost>
Apache VirtualHost docs: http://httpd.apache.org/docs/2.2/vhosts/
Apache VirtualHost文档:http://httpd.apache.org/docs/2.2/vhosts/
This needs the mod_proxy Apache
module. It might be installed already.
这需要mod_proxy Apache模块。它可能已经安装。
#2
You should configure Tomcat with Apache using AJP Connector/mod_jk(the Tomcat redirector module).
您应该使用AJP Connector / mod_jk(Tomcat重定向器模块)将Apache配置为Apache。
There are many articles if you google :
如果你谷歌有很多文章:
- Apache Tomcat Connector - Webserver HowTo
- Tomcat and Apache Setup
- Integrating Tomcat and Apache
Apache Tomcat Connector - Webserver HowTo
Tomcat和Apache安装程序
集成Tomcat和Apache