Apache subdomain redirect into Tomcat

元气小坏坏 提交于 2019-11-29 04:13:03

问题


I'm pretty new to Apache HTTP, and sysadmin-ing in general, so i have this question I have a domain (www.doamin.com) with an Apache listening to port 80, also I have an Apache Tomcat on the same domain configured to port 8080.

Is there a way to configure a subdomain (i.e, tomcat.domain.com) so it will redirect into my tomcat specific application, so user can access applications through app1.domain.com and app2.domain.com (and it will be served by Tomcat)?

I've seen a lot of mentioning to

mod_jk

and

mod_proxy

but all of the post assumed prior knowledge with Apache. can someone walk me thorugh?

Many thanks, -PK.


回答1:


mod_jk is outdated. It is recomended to use mod_proxy (mod_proxy_http or mod_proxy_ajp) to connect forward requests to your apache server to the tomcat.

  1. define a virtual host in your apache config
  2. create a proxy directive that forwards your requests to tomcat

Maybe this SO question give you some hints.

You can define two virtual hosts (app1.domain.tld and app2.domain.tld) that have proxy definitions for their designated apps. Example for app1:

<VirtualHost *:80>
    ServerName app1.domain.tld
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/app1
    ProxyPassReverse / http://localhost:8080/app1
</VirtualHost> 



回答2:


while Magomi was almost right,

Presenting an exact way to do it.

  1. Add your subdomain to the DNS server

  2. integrate *mod_proxy* into httpf.conf :

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
  1. define two virtual hosts as following

    NameVirtualHost *:80

    <VirtualHost *:80>
        ServerName application.domain.com
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
        ProxyPass / http://www.domain.com:8080/application/
        ProxyPassReverse / http://www.domain.com:8080/application/
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot C:\<pathToApache>\www
        ServerName www.domain.com
    </VirtualHost>
    

This will direct your site (www.domain.com) to your Apache HTTP server, and redirect all calls to Application to the Tomcat.

Hope this Helps,

-PK



来源:https://stackoverflow.com/questions/10200204/apache-subdomain-redirect-into-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!