0

I am setting up a server running on Ubuntu 14.04. I have apache and tomcat installed with the rewrite module for apache and mod_jk enabled. I have mod_jk properly configured so apache is forwarding the request to the app context correctly. I also have the domain name pointed correctly at the server and am able to browse to it. However, I am having issues with my virtual host file. I am attempting to point a domain at the application running within tomcat. Here is what I have currently as a virtual host file.

<VirtualHost *:80>
    ServerName www.domain.com
    DocumentRoot /var/www/domain

    RewriteEngine On
    RewriteRule \/$ /context [L]
</VirtualHost>

I have tried many variations of this but have had no luck. Any help to resolve would be most appreciated.

** Update **

I am able to produce a rewrite to a directory named after the tomcat application, in this example context in my apache html folder (/var/www/html/context). Here is what my virtual host file now looks like :

<VirtualHost *:80>                                                       
        ServerName www.domain.com                                
        DocumentRoot /var/www/html/context/  

        <Directory />                                                    
                Options FollowSymLinks                                   
                AllowOverride None                                       
                RewriteEngine On                                         
                RewriteRule \/$ /context [L]                                
        </Directory>                                                     

        <Directory /var/www/html/context/>                                  
                Options Indexes FollowSymLinks MultiViews                
                AllowOverride None                                       
                Order allow,deny                                         
                allow from all                                           
        </Directory>                                                    
</VirtualHost> 

The problem now is it is not rewriting to the tomcat application named context. So to sum it all up :

http://{{ip_address}}/context - works like it should and displays the tomcat application

http://domain.com - redirects me to html content within /var/www/html/context

How can I force the rewrite rule to redirect to the tomcat application name context? Is there a global setting that will override rewrites and instead of displaying content within apaches html directory to applications mounted with mod_jk?

Thanks in advance for your help.

0

Update2

   <VirtualHost *:80>
        ServerName www.domain.com
        ServerAlias 10.10.10.10(server's IP) server'sFQDN 
        DocumentRoot /var/www/domain

        RewriteEngine On
        # Rewrite everything after ' / ' to /context/restofURLifany
        RewriteRule ^/(.*)$ /context/$1 [L,QSA,PT]
        # Rewrite ' / ' to /context
        #RewriteRule ^/$ /context [L,PT]
        # Send all '/context' traffic to prod loadbalancer ' prod_lb '
        JkMount /context prod_lb

        # Send all other traffic from root domain ' / ' to prod loadbalancer ' prod_lb '
        JkMount /* prod_lb

    </VirtualHost>

Edit /etc/hosts and add a line like this at the top:

#IPaddr hostnames
10.10.10.10 serverFQDN hostname www.domain.com

I'm assuming your problem is that the domain name you are using apache isn't associating with that virtual host.

In httpd.conf add: NameVirtualHost *:80

Update

Is this what you are looking for?

RewriteRule ^/(.*)$ /context/$1 [L,QSA,PT]

If you have mod_jk installed, this should help point you in the right direction:

In virtualhost conf

<VirtualHost *:80>
    ServerName www.domain.com
    DocumentRoot /var/www/domain

    # Send all traffic from root domain ' / ' to prod loadbalancer ' prod_lb '
    JkMount /* prod_lb

</VirtualHost>

In workers.properties file

# Define list of workers that will be used for mapping requests
worker.list=prod_lb,status

# Define Tomcat App Node1
# modify the host as your host IP or DNS name.
worker.node1.port=9999 #AJP1.3 port Tomcat listening on
worker.node1.host=127.0.0.1 #Insert FQDN or IP here (I prefer IPs for speed)
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=1
worker.node1.max_packet_size=16384
worker.node1.connect_timeout=10000
worker.node1.prepost_timeout=10000
worker.node1.socket_timeout=5000
worker.node1.socket_keepalive=True
worker.node1.reply_timeout=30000
worker.node1.max_reply_timeouts=3
worker.node1.recovery_options=0
worker.node1.domain=group1
worker.node1.stopped=false

# Load-balancing behavior
worker.prod_lb.type=lb
worker.prod_lb.balance_workers=node1
worker.prod_lb.max_reply_timeouts=10
worker.prod_lb.method=Session
worker.prod_lb.lock=P
worker.prod_lb.sticky_session=1
worker.status.type=status

Tomcat's server.xml

<!-- Define an AJP 1.3 Connector on port -->
<Connector port="9999" address="${jboss.bind.address}" protocol="AJP/1.3" 
   maxThreads="300" connectionTimeout="5000" maxHttpHeaderSize="16384" packetSize="16384" 
   emptySessionPath="true" enableLookups="false" />

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="tomcat_node1">
  • Thanks, I tried 'RewriteRule ^/(.*)$ /context/$1 [L,QSA,PT]' but produced 'The requested URL /context was not found on this server'. However I can browse to http://{{ip_address}}/context without issue. – mcroteau Jan 16 '15 at 20:39
0

I edited my virtual host file. I added the JkMount inside the virtual host file instead of 000-default.conf and was able to get apache to pass the request to the tomcat application instead of the folder in apaches web directory. I also now have 2 virtual host files, one for the main domain and the other for the domain without www. prefix. Here is what the 2 files look like :

www_domain.conf

<VirtualHost *:80>

        ServerName www.domain.com

        JkMount /context* ajp13_worker

        <Directory />
                Options FollowSymLinks
                AllowOverride None
                RewriteEngine On
                RewriteRule \/$ /context [L]
        </Directory>

</VirtualHost>

domain.conf

<VirtualHost *:80>
        ServerName domain.com

        RewriteEngine On
        RewriteRule \/$ http://www.domain.com [L] 
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.