Results 1 to 4 of 4

Thread: how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

  1. #1
    Join Date
    Sep 2008
    Beans
    721
    Distro
    Ubuntu 12.04 Precise Pangolin

    how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

    how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

    I am running on tomcat server that has webapps listening on 8080

    I would like to host these webapps on different domains.

    For example, if the public virtual host is www.foobar.com and the friendly URL is /foobar, then www.foobar.com is mapped to http://www.hostdomain.com/dir/foobar

    How can I achieve this?

    I have tried several things without success.

    I was thinking I should have server to
    1 - Grab the wild subdomain from the domain
    2 - Make sure the subdomain is not www, w or ww
    3 - Check if the directory actually exists on "www.domain.com" before rewrite
    4 - if the directory doesnt exist it stays as wild domain
    5 - Finally, if the directory exist the actual rewrite

    I couldnt make it work with mod_rewrite alone. I have been looking into mod_proxy, mod_proxy_ajp, and mod_rewrite


    Code:
    <VirtualHost *:80>
    	ServerAdmin webmaster@localhost
    	ServerName www.domain.com
    	ServerAlias www.domain.com domain.com *.domain.com
    	RedirectPermanent / http://www.domain.com
    	DocumentRoot /var/www
    	<Directory />
    		Options FollowSymLinks
    		AllowOverride None
    	</Directory>
    	<Directory /var/www/>
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride All
    		Order allow,deny
    		allow from all
    	<IfModule mod_rewrite.c>	
                    Options +FollowSymLinks
                    Options +Indexes
    
                    RewriteEngine On
                    RewriteBase /
    
                    # Prevent looping this rule
                    RewriteCond %{ENV:REDIRECT_STATUS} !200
                    RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
                    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
                    RewriteRule (.*) /%2/$1 [L]
    
                    # change the "." in the path to "/"
                    RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
    
                    #redirect domain.com to www.domain.com
                    RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
                    RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,NC]	
    	</IfModule>	
    	</Directory>
    
    	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    	<Directory "/usr/lib/cgi-bin">
    		AllowOverride None
    		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    		Order allow,deny
    		Allow from all
    	</Directory>
    
    	ErrorLog /var/log/apache2/error.log
    
    	# Possible values include: debug, info, notice, warn, error, crit,
    	# alert, emerg.
    	LogLevel warn
    
    	CustomLog /var/log/apache2/access.log combined
    
        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>
    	<Proxy *>
    	Order deny,allow
    	Allow from all
    	</Proxy>
    
    #	ErrorLog /var/log/apache2/foobar_error.log
    #	LogLevel warn
    #	CustomLog /var/log/apache2/foobar_access.log combined
    	
    	ProxyPass / ajp://localhost:8009/
    	ProxyPassReverse / ajp://localhost:8009/
    
    #	ProxyPass        /user/ http://localhost:8080/user/foobar/
    #	ProxyPassReverse /user/ http://localhost:8080/user/foobar/
    
    #	ProxyPass        /foobar/ http://localhost:8080/web/foobar/
    #	ProxyPassReverse /foobar/ http://localhost:8080/web/foobar/
    
    #	ProxyPass        / http://localhost:8080/web/foobar/
    #	ProxyPassReverse / http://localhost:8080/web/foobar/
    
    </VirtualHost>
    Last edited by 007casper; September 9th, 2012 at 01:36 AM.
    Using 12.04 Ubuntu

  2. #2
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,657
    Distro
    Ubuntu

    Re: how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

    Thread moved to Server Platforms.

  3. #3
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    11,405
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

    Quote Originally Posted by 007casper View Post
    For example, if the public virtual host is www.foobar.com and the friendly URL is /foobar, then www.foobar.com is mapped to http://www.hostdomain.com/dir/foobar

    How can I achieve this?
    If you don't mind that www.hostdomain.com/dir/foobar appears in the address bar, then you can just use simple redirects in Apache:

    Code:
    <VirtualHost *:80>
         ServerName     www.foobar.com
         ServerAlias    foobar.com <=optional
    
         Redirect / http://www.hostdomain.com/dir/foobar
    </VirtualHost>
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Jan 2010
    Location
    Portugal
    Beans
    160
    Distro
    Ubuntu Development Release

    Re: how to virtualhost mod_rewrite mod_proxy on apache2 + tomcat - java server

    Hello!

    I'm not a big user of Tomcat. I remember i did something related with that. Had to use something called workers.

    Try to see if this helps you:
    http://blog.tele-lab.org/2010/03/con...virtual-hosts/

    Regards!
    Javali
    Administração e Desenvolvimento de Sistemas Informáticos, Lda.
    Open Source Systems / SugarCRM / Alfresco / Drupal / Openbravo
    http://www.javali.pt info at javali.pt

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •