Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Linux VPS. Configuration Linux CentOS with cPanel Default port :80

Servers running Apache for PHP (default in cPanel) Tomcat 5.5.33

I have a only 1 IP alloted for it. Have multiple domains hosted on it.

MY PROBLEM: All domains are running on port :80 but i need only 1 of my domain to run in port :8080

I'm able to access my domain as www.example.com:8080 but i need to access it as www.example.com (8080 should deliver instead of default 80)

My references http://httpd.apache.org/docs/2.0/vhosts/examples.html http://library.linode.com/lamp-guides/centos-6

share|improve this question

3 Answers 3

If I understand correctly, you want to transparently access the tomcat content on www.example.com:8080 by simply accessing www.example.com - there's a few methods to do this:

1) if you have mod-rewrite enabled, try something like this in your vhost definition or in a .htaccess file

RewriteEngine on
RewriteCond  %{SERVER_PORT} !^8080$
RewriteRule ^(.*) http://%{SERVER_NAME}:8080%{REQUEST_URI} 

2) if you wanna back-proxy it (needs mod_proxy_http enabled) http://tomcat.apache.org/connectors-doc-archive/jk2/proxy.html

share|improve this answer
The port forwarding is working. But i need to mask the 8080 port from browser view. Also If i need to forward the above to some subfolder as default, how can i make it? RewriteRule ^(.*) http://%{SERVER_NAME}:8080/sub%{REQUEST_URI} is causing problem while i try to access example.com/admin in browser (it redirects to example.com/sub/admin 404error ) –  mohan.hab Aug 20 '11 at 8:01
@mohan.hab, if you want to "mask the 8080 port" (i.e. use port 80), you need to use one of the reverse proxy methods, not mod_rewrite. –  Bruno Aug 20 '11 at 12:41

You get two categories of options: redirection or reverse proxy (which you can do within a specific VirtualHost configuration, if you need this to be for only one host name).

The redirection can be done using mod_rewrite (as @O G says).

Since the server running on port 8080 is effectively a different server from Apache HTTPD on port 80, mod_rewrite can't rewrite URLs internally (so it only works in redirection mode). Instead, you can use a reverse proxy method:

  • mod_jk2 (from @O G's link) is considered "historical".
  • mod_jk is rather stable, but it relies on the AJP protocol, so you wouldn't need to enable it on your Tomcat configuration (probably not on port 8080).
  • mod_proxy_ajp is also rather stable and often comes by default with Apache HTTPD (unlike mod_jk), at least with version 2.2. It also uses the AJP protocol, so you would need to configure Apache Tomcat accordingly too.
  • Otherwise, you could use an HTTP reverse proxy, with mod_proxy_http (without the need for AJP).
share|improve this answer
up vote 0 down vote accepted

I had found solution from the hints given in previous posts

.htaccess file

RewriteEngine on
RewriteBase /
RewriteRule ^admin(.*)$ http://example.com/tryAdmin$1 [R,L]
RewriteRule ^(.*)$ http://example.com/try/$1 [R,L]


ProxyPass         /try  http://example.com:8080/try
ProxyPassReverse  /try  http://example.com:8080/try
ProxyPass         /tryAdmin  http://example.com:8080/tryAdmin
ProxyPassReverse  /tryAdmin  http://example.com:8080/tryAdmin

References http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html#Apache_2.0_Proxy_Support

Apache - /etc/httpd/conf/httpd.conf Tomcat - /usr/local/jakarta/apache-tomcat-5.5.33/conf/server.xml


share|improve this answer

Your Answer


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.