Configure a Reverse Proxy with Apache

In a previous post, I discussed the details required to set up Subsonic on Ubuntu Server. The problem with Subsonic is that it runs on Tomcat on a non-standard port. The rest of my web applications run in Apache on port 80. Therefore, it would be nice if instead of having to go to http://athos.zacintosh.com:8180/subsonic/, I could simply go to http://athos.zacintosh.com/subsonic/. The solution is called a reverse proxy. Reverse proxies can do things like load balance between multiple web servers or simply make resources on an internal web server available externally. In this case, I am using a reverse proxy to make a web application available on a different port available on the standard port 80.

The set up is fairly simple. On Ubuntu, it should be as simple as issuing this command (as root) to enable the proxy modules:

a2enmod proxy_http

Next I inserted the following into /etc/apache2/conf.d/subsonic.conf to make it available on all websites running on my server. If you only wanted it to be available for a single website, you could insert this into a site inside of /etc/apache2/sites-available/.

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass /subsonic/ http://localhost:8180/subsonic/
ProxyPassReverse /subsonic/ http://localhost:8180/subsonic/

The configuration above says to not proxy all requests (not act as a forward proxy server). The ProxyPass and ProxyPassReverse set up the actual retrieval of data from Subsonic running on Tomcat. You need to replace the localhost and the port number with the specific items for your configuration. Finally, you need to reload the Apache configuration:

/etc/init.d/apache2 force-reload

Now Subsonic should be available on port 80 just like everything else running on your web server with Apache.

13 thoughts on “Configure a Reverse Proxy with Apache

  1. Pingback: Install Subsonic on Ubuntu Server « blog.lundscape.com

  2. Zachary Lund Post author

    @Rick, This particular example is for Subsonic which requires Tomcat. Therefore, Tomcat handles serving Subsonic, and Apache handles forwarding the requests.

  3. Gavin

    Hi,

    I cannot setup the subsonic with port 80 access. Currently, the subsonic works well with 8080.

    My steps after setup the subsonic standalone for my Ubuntu 8.04 LTS.

    1. a2enmod proxy_http —> OK
    2. create file /etc/apache2/conf.d/subsonic.conf (as it is missing by default)
    3. Fill in the code
    ProxyRequests Off
    ProxyPreserveHost On

    Order allow,deny
    Allow from all

    ProxyPass /subsonic/ http://192.168.0.115:8080/subsonic/
    ProxyPassReverse /subsonic/ http://192.168.0.115:8080/subsonic/
    4. Set the CONTEXT_PATH of the subsonic.sh
    5. Restart the apache server

    But I cannot fail. HTTP 404 showed.

  4. Zachary Lund Post author

    @Gavin, What operating system are you running? My directions are specific to the Ubuntu/Debian varieties. If you are running something else, it’s possible that your subsonic.conf file is not being seen. You could try putting the configuration in another Apache configuration file that you know will be sourced.

    Just a sanity check, you are able to get to the Subsonic server on port 8080 at the same time you are not able to get to it on port 80, correct?

  5. Pingback: accessing to DB systems installed in 2 servers through one single public IP

  6. Lopti

    After using this tutorial, I’ve encounter a problem : apache seem to redirect http://toto/subsonic to http://toto:4040.

    After investigation, I edit subsonic config (/etc/default/subsonic in debian) to add –context-path=/subsonic parameter.

    Ex of config file :
    SUBSONIC_ARGS=”–max-memory=150 –port=4040 –context-path=/subsonic”

    And it work fine now.

  7. Sagisyana

    Hi Experts,
    I have installed the apache server on the linux machine successfully. But when i try to make a request the response body is getting truncated.

    Kindly suggest how to proceed.

  8. Sepehr

    Hi
    Thanks for your post.
    I have done this and have a problem that hope you can help me.

    I have set up an Apache reverse proxy on server A that maps address: address1.com/app to ipaddress/app2. in the target page there’s a login form, which uses a post method and calling a php file and it works fine. But same time I have another sign up form that the submit button is linked to the “#” and is using java script for processing it, the problem starts when I click the submit button and it calls: address1.com/app1/app1 and so tries to open ipaddress.com/app2/app1 which doesn’t exist. I think maybe I need to use rewrite mode for solving it but after some works I couldn’t. I appreciate your kind help if you can.
    This is the code for the signup button: .
    As in the private application I’ll have more than one form and the code is complex I prefer not changing that part.

    Many thanks

  9. Zachary Lund Post author

    @Sepehr,

    I’m having a little trouble following your setup.

    Generally, I’ve always found it easier to keep the path portion of the URL the same: address1.com/app to ipaddress/app will work better than address1.com/app1 to ipaddress/app2.

    Do all of your URLs work correctly when you browse to the IP address? It sounds like you might have a link to “app1″ when you should actually have a link to “/app1″.

    Good luck.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>