In addition to the default Apache on AWS EC2 Linux I have installed Tomcat 8 and deployed a webservice on it.

The current URL (which works) is http://example.com:8080/MyService/api/generatePath

I want to make this shorter with a subdomain api.mydomain.com, so that I can use this URL: http://api.example.com/generatePath.

This is what I have done on the /etc/httpd/conf/httpd.conf, but it doesn't work:

<VirtualHost *:80>
    ServerName api.example.com
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny,allow
        Allow from all
    ProxyPass / http://localhost:8080/MyService/api
    ProxyPassReverse / http://localhost:8080/MyService/api

First have you enabled mod proxy on apache? Secondly try remove ProxyPreserveHost On

In addition make sure the port is opening; easiest way to check is go to http://www.yougetsignal.com/tools/open-ports/ (Enter website address and port 80)

Hope this helps


(1) To remove the /MyService/ part of your url, rename your MyService.war file to ROOT.war and copy it to your webapps folder using sudo cp. Normally, your tomcat installation is expected to automatically generate a ROOT directory in the same folder.

(2) To remove the :8080, access the site via :80 instead which is not listed on the URL bar, using the installed httpd.conf you stated. Edit the following two things to look like this.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<VirtualHost *:80>
    ServerName api.example.com

    ProxyRequests On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    <Location "/">
            Order allow,deny
            Allow from all

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.