Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am in a hosting fix! I have developed a web app for my organisation that allows sharing, interacting, etc. I want to DEPLOY IT ON LAN. BUT...

I don't want the end user to type: 10.21.34.56:8080/webapp

Instead I want him to type: http://www.webapp.com and let the local DNS on the intranet resolve it to the corresponding IP.

I can do a little..I succeed in this: "www.webapp.com:8080".

I don't want the 8080 to be typed.

Though I found a way to do this. I am not fully satisfied.

The browser by default sends all the http requests to port 80. So, I used iptables on the server, and redirected the request to port 8080. That didn't seem worthwhile discovery.

SO, I hear about virtual hosting on apache-tomcat, which they say is a solution to this.

Show me light!

share|improve this question
    
Is there already a site @ www.webapp.com? –  frogstarr78 Sep 29 '11 at 1:56
    
@Abhishek so you figured it out? –  Nikhil Mulley Jan 15 '12 at 7:25
add comment

2 Answers 2

As far as I understand your question, you are asking for port redirection from apache at port 80 to your tomcat appserver running at 8080 port, at the same time have your apache mask the port in http headers and have users do not have to explicitly type the port number in the browsing url. This needs Application bridging between Apache and your tomcat application server running on the same host. Assuming that you are going to host a apache virtualhost on the host, you need to configure dns to point application CNAME to the host.

You can do this in many ways. One of the methods are in no particular order(but may be in terms of easiness of setup relatively)

  • mod_rewrite & mod_proxy apache module. Easy to setup. Only involves httpd configuration. Just acts as proxy rewrite for http traffic at port 80 destined for the virtual host to tomcat http server. So far, I find this to be pretty neat and simple, from administration point of view. I will let the developer/app-manager responsible for tomcat installation take care of updating the server.xml file.

    Reference: http://tomcat.apache.org/tomcat-5.5-doc/proxy-howto.html Example:

    <VirtualHost *:80>
    ServerName yourapp.yourdomain.com
    ServerAlias yourapp.*        
    ProxyRequests Off
    ProxyPreserveHost On     
    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>     
    ProxyPass /webapp http://localhost:8080/webapp
    ProxyPassReverse /webapp http://localhost:8080/webapp    
    <Location /webapp>
      Order allow,deny
      Allow from all
    </Location>        
    </VirtualHost>
    
  • Running JSP Through Apache using mod_jk2 module. Medium hard. Involves complex parameter setup in httpd configuration, useful if the same virtual host needs to execute other scripts such as php/perl/cgi other than passing the traffic to Tomcat server. There is an excellent HOWTO in these links.

    Reference:

    http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

    http://people.apache.org/~mturk/docs/article/ftwai.html

    http://www.mulesoft.com/apache-tomcat-mod-jk-connector-configuration

  • Run JSP through Apache mod_proxy_ajp module: Its similar to the above approach, but this module aligns with using ajp protocol communication with tomcat instead of http for the sake of consistency.

    References:

    https://confluence.sakaiproject.org/display/~steve.swinsburg/Fronting+Tomcat+with+Apache+via+mod_proxy_ajp

  • Solve this at the network layer of the host. Use iptables to redirect all the incoming traffic at port 80 bind to port 8080 by default. Involves understanding and managing the iptables settings. One time setup, but difficult to maintain. Can get problematic, if you have to host other Apache virtualhosts on the same machine.

Example:

iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -A OUTPUT -d $(/bin/hostname) -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -d $(/bin/hostname) -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables-save
share|improve this answer
    
If you are in a dilemma of which mod_* module to choose from, here is a helping document to decide: tomcatexpert.com/blog/2010/06/16/… –  Nikhil Mulley Jan 14 '12 at 18:32
add comment

DNS associates a host name with an IP address. It knows nothing about specific ports. If you don't specify a port in the URL, then the browser will contact the IP address returned by DNS, on port 80. Reditecting port 80 to port 8080 with iptables is the right solution.

share|improve this answer
    
redirecting port 80 to port 8080 with iptables is appropriate unless there are other virtual hosts/static web content/ to be served off the apache server; which can get difficult if all the traffic is redirected to tomcat application server. –  Nikhil Mulley Jan 14 '12 at 18:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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