Proxy Apache Httpd And Tomcat (Wiki forum at Coderanch) (original) (raw)
This describes a way to proxy Tomcat requests through Apache Httd Web Server. I found mod_jk way overly complicated for development purposes. Whether or not proxies are a good idea in production, I do not know.
************************* Warning !!! **************************************************
I found this article while doing a search and noticed some very bad code, specifically this:
The above code will allow anyone to forward stuff like spam through your Apache server!!
I think that the original author really wanted to set up a reverse proxy, not a forward proxy.
Forward proxies are used for things like providing Intranet members with a connection to the Internet. Reverse proxies are used for clustering, load balancing, etc.
Unless you know what you are doing a good rule of thumb is to NEVER include this directive in your httpd.conf file:
In fact, unless you are truly creating a forward proxy, you should ALWAYS include this directive:
I have not changed anything in this article other than to add this warning.
H. Hall
I am assuming the following versions of Apache Httpd and tomcat
Apache Httpd 2.0.59
Tomcat 5.5.20
I am currently running Xubuntu Edgy and have installed Apache2 using apt-get.
First, you need to enable proxies in Apache. You can do the following commands from anywhere on the filesystem.
sudo ln -s /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf
sudo ln -s /etc/apache2/mods-available/proxy_http.load /etc/apache2/mods-enabled/proxy_http.load
sudo ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load
Next, edit /etc/apache2/mods-available/proxy.conf with your favorite editor (like VIM) and turn proxies on for All domains. (You can also restrict to specific domains, but since this is local machine development, this is just as easy)
Now that proxies are enabled, we need to define one. Create a file with the same name as your web application context in the following location:
/etc/apache2/sites-available/
For this example, our app is called testApp. Using your favorite editor (like VIM) use the following configuration:
DocumentRoot points to the location where you are serving static content from, like images, styles, scripts, etc. The ProxyPass and ProxyPassReverse tells apache httpd to send all dynamic requests to Tomcat.
Now, provide a sym link for this site in /etc/apache2/sites-enabled
sudo ln -s /etc/apache2/sites-available/testApp /etc/apache2/sites-enabled/testApp
The last thing is to edit your hosts file (/etc/hosts) to include the ServerName you have specified:
127.0.0.1
Now, just restart Apache (sudo apache2ctl restart) and you should be good to go. So now, rather than using port 8080, you would access your web app using the following: