John is an experienced consultant specialising in Enterprise Java, Web Development, and Open Source technologies, currently based in Sydney, Australia. Well known in the Java community for his many published articles, and as author of Java Power Tools and Jenkins: The Definitive Guide, and founder of the open source Thucydides Automated Acceptance Test Library project, John helps organisations to optimize their Java development processes and infrastructures and provides training and mentoring in agile development, automated testing practices, continuous integration and delivery, and open source technologies in general. John is the CEO of Wakaleo Consulting, and runs several Training Courses on open source Java development tools and best practices. John is a DZone MVB and is not an employee of DZone and has posted 125 posts at DZone. You can read more from them at their website. View Full User Profile

Running Hudson Behind an Apache Server: a Primer

05.26.2010
| 4740 views |
  • submit to reddit

If you are running Hudson in a Unix environment, you may want to hide it behind an Apache HTTP server in order to harmonize the server URLs and simplify maintenance and access. This way, users can access the Hudson server using a URL like http://myserver.myorg.com/hudson rather than http://myserver.myorg.com:8081. One way to do this is to use the Apache mod_proxy and mod_proxy_ajp modules. In this article, we discuss one approach.

The exact configuration of this module will vary depending on the details of your Apache version and installation details, but one possible approach is outlined in this article.

First, if you are running Hudson as a stand-alone application, make sure you start up Hudson using the --prefix option. The prefix you choose must match the suffix in the public-facing URL you want to use. So if you want to access Hudson via a URL like http://myserver.myorg.com/hudson, you will need to provide 'hudson' as a prefix:

$ java -jar hudson.war --httpPort=8081 --ajp13Port=8010 --prefix=hudson
If you are running Hudson on an application server such as Tomcat, Hudson will already have its own web context ("/hudson" by default).

Next, make sure the mod_proxy and mod_proxy_ajp modules are activated. In your httpd.conf file (often in the /etc/httpf/conf directory), you should have the following line:

LoadModule proxy_module modules/mod_proxy.so

The proxy is actually configured in the proxy_ajp.conf file (often in the /etc/httpd/conf.d directory). An example of such a configuration file is given here:

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
ProxyPass /hudson http://localhost:8081/hudson
ProxyPassReverse /hudson http://localhost:8081/hudson
ProxyRequests Off

Once this is done, you just need to restart your Apache server:

$ sudo /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
Now you should be able to access your Hudson server using a URL like http://myserver.myorg.com/hudson.

This is one approach - there are others. I'd be curious to hear about alternative configurations that people are using or issues people have come across.

From http://www.wakaleo.com/blog/269-running-hudson-behind-an-apache-server-a-primer

Published at DZone with permission of John Ferguson Smart, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Marc Ende replied on Wed, 2010/05/26 - 5:02am

Hi John,

 I think there is a little issue in the description.You're loading mod_proxy_ajp but you aren't using it.

The proxy-pass directives all use http and the http-port 8081. I think you've meant this:

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
ProxyPass /hudson ajp://localhost:8010/hudson
ProxyPassReverse /hudson ajp://localhost:8010/hudson
ProxyRequests Off
m.

Jozsef Kozell replied on Wed, 2010/05/26 - 6:13am in response to: Marc Ende

In standalone mode, hudson's ajp is broken. This will only work if you run hudson in a (e.g.) Tomcat instance. More: http://issues.hudson-ci.org/browse/HUDSON-5753

John Ferguson Smart replied on Wed, 2010/05/26 - 4:35pm

Thanks Marc,

You're right, well-spoted - in fact I'm not actually using the mod_proxy_ajp, only mod_proxy. The code in the example is what I've got running in production, though, so in fact you don't actually need AJP if you're using Winstone. Thanks for the clarification on the Winstone bug Jozsef.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.