Apache HTTPD, Hudson and Tomcat

Hudson Prefix

We want to see hudson running on servername/hudson/. The first step is to change the prefix hudson uses, so we get from servername:8080/ to servername:8080/hudson/. To do that pico /etc/default/hudson, add

–prefix=/hudson to below line.

HUDSON_ARGS="–webroot=/var/run/hudson/war –httpPort=$HTTP_PORT –ajp13Port=$AJP_PORT –prefix=/hudson"

sudo /etc/init.d/hudson force-reload

apt-get install apache2

apt-get install libapache2-mod-proxy-html

a2enmod proxy

a2enmod proxy_http

By default it is configured to deny all proxying, so edit /etc/apache2/mods-enabled/proxy.conf to allow proxying:

ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

In your /etc/apache2/sites-enabled/ directory there should be some file like 000-default or similar, with settings for the site. Add proxy configurations in it for mapping the /hudson path on the website to localhost:8080/hudson:

pico /etc/apache2/sites-enabled/000-default

and add below:


###ProxyPass /hudson http://http:8080/hudson

ProxyPass /hudson http://127.0.0.1:8080/hudson
ProxyPassReverse /hudson http://127.0.0.1:8080/hudson
ProxyRequests Off
# Local reverse proxy authorization override
# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
<Proxy http://127.0.0.1:8080/hudson*>
Order deny,allow
Allow from all
</Proxy>

Restart Apache2

/etc/init.d/apache2 force-reload

=====================================

IGNORE BELOW

=====================================

In situations where you have existing web sites on your server, you may find it useful to run Hudson (or the servlet container that Hudson runs in) behind Apache, so that you can bind Hudson to the part of a bigger website that you may have. This document discusses some of the approaches for doing this.

Make sure that you change the Hudson httpListenAddress from its default of 0.0.0.0 to 127.0.0.1 or any Apache-level restrictions can be easily bypassed by hitting the Hudson port directly.

mod_proxy

mod_proxy works by making Apache perform "reverse proxy" — when a request arrives for certain URLs, Apache becomes a proxy and further forward that request to Hudson, then it forwards the response back to the client.

The following Apache modules must be installed :

a2enmod proxya2enmod proxy_http

A typical set up for mod_proxy would look like this:

ProxyPass         /hudson  http://localhost:8081/hudsonProxyPassReverse  /hudson  http://localhost:8081/hudsonProxyRequests     Off# Local reverse proxy authorization override# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)<Proxy http://localhost:8081/hudson*>Order deny,allowAllow from all</Proxy>

This assumes that you run Hudson on port 8081.

For this set up to work, the context path of Hudson must be the same between your Apache and Hudson (that is, you can't run Hudson on http://localhost:8081/ci and have it exposed at http://localhost:80/hudson).

Set the context path in Windows by modifying the hudson.xml configuration file and adding –prefix=/hudson (or similar) to the <arguments> entry.

The ProxyRequests Off prevents Apache from functioning as a forward proxy server (except for ProxyPass), it is advised to include it unless the server should function as a proxy.

If you are running Apache on a Security-Enhanced Linux (SE-Linux) machine it is essential to make SE-Linux do the right thing by issuing as root
																					setsebool -P httpd_can_network_connect true
			

If this is not issued Apache will not be allowed to forward proxy requests to Hudson and only an error message will be displayed.

Because hudson already compress its output, you can not use the normal proxy-html filter to modify urls:
																					SetOutputFilter proxy-html
			

Instead you can use the following:

																					SetOutputFilter INFLATE;proxy-html;DEFLATE			ProxyHTMLURLMap http://your_server:8080/hudson /hudson
			

http://wiki.uniformserver.com/index.php/Reverse_Proxy_Server_2:_mod_proxy_html_2
But since hudson seems to be well behaved it even better to just not use SetOutputFilter and ProxyHTMLURLMap.

If there are problems with hudson sometimes servicing random garbage pages, then the following may help:
																					SetEnv proxy-nokeepalive 1
			

mod_proxy with HTTPS

If you'd like to run Hudson with reverse proxy in HTTPS, one user reported that HTTPS needs to be terminated at Hudson, not at the front-end Apache. See this e-mail thread for more discussion.

Alternatively, you can add an additional ProxyPassReverse directive to redirect non-SSL URLs generated by Hudson to the SSL side. Assuming that your webserver is your.host.com, placing the following within the SSL virtual host definition will do the trick:

ProxyRequests     OffProxyPreserveHost On<Proxy http://localhost:8081/hudson*>Order deny,allowAllow from all</Proxy>ProxyPass         /hudson  http://localhost:8081/hudsonProxyPassReverse  /hudson  http://localhost:8081/hudsonProxyPassReverse  /hudson  http://your.host.com/hudson

Yet another option is to rewrite the Location headers that contain non-ssl URL's generated by Hudson. If you want to access hudson from https://www.example.com/hudson, placing the following within the SSL virtual host definition also works:

ProxyRequests     OffProxyPreserveHost OnProxyPass /hudson/ http://localhost:8081/hudson/<Location /hudson/>ProxyPassReverse /Order deny,allowAllow from all</Location>Header edit Location ^http://www.example.com/hudson/ https://www.example.com/hudson/

mod_ajp/mod_proxy_ajp

More info welcome. Probably we should move the contents from here

I wanted to have Hudson running in a different workspace than my normal Tomcat server, but both available via the Apache web server. So, first up, modify Hudson to use a different web and ajp port than Tomcat:

HTTP_PORT=9080AJP_PORT=9009...nohup java -jar "$WAR" --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --prefix=/hudson >> "$LOG" 2>&1 &

Then setup Apache so that it knows that the prefix /hudson is being served by AJP in the httpd.conf file:

LoadModule jk_module          libexec/httpd/mod_jk.soAddModule     mod_jk.c#== AJP hooks ==JkWorkersFile /etc/httpd/workers.propertiesJkLogFile     /private/var/log/httpd/mod_jk.logJkLogLevel    infoJkLogStampFormat "[%a %b %d %H:%M:%S %Y] "JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectoriesJkRequestLogFormat     "%w %V %T"# Here are 3 sample applications - 2 that are being served by Tomcat, and HudsonJkMount  /friki/* worker1JkMount  /pebble/* worker1JkMount  /hudson/* worker2

Then finally the workers.conf file specified above, that just tells AJP which port to use for which web application:

# Define 2 real workers using ajp13worker.list=worker1,worker2# Set properties for worker1 (ajp13)worker.worker1.type=ajp13worker.worker1.host=localhostworker.worker1.port=8009worker.worker1.lbfactor=50worker.worker1.cachesize=10worker.worker1.cache_timeout=600worker.worker1.socket_keepalive=1# Set properties for worker2 (ajp13)worker.worker2.type=ajp13worker.worker2.host=localhostworker.worker2.port=9009worker.worker2.lbfactor=50worker.worker2.cachesize=10worker.worker2.cache_timeout=600worker.worker2.socket_keepalive=1worker.worker2.recycle_timeout=300

mod_rewrite

Some people attempted to use mod_rewrite to do this, but this will never work if you do not add a ProxyPassReverse.
See the thread if you'd like to know why.

The following Apache modules must be installed :

a2enmod rewritea2enmod proxya2enmod proxy_http

A typical set up for mod_rewrite would look like this:

# Use last flag because no more rewrite can be applied after proxy passRewriteRule       ^/hudson(.*)$  http://localhost:8081/hudson$1 [P,L]ProxyPassReverse  /hudson        http://localhost:8081/hudsonProxyRequests     Off# Local reverse proxy authorization override# Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)<Proxy http://localhost:8081/hudson*>Order deny,allowAllow from all</Proxy>

This assumes that you run Hudson on port 8081. For this set up to work, the context path of Hudson must be the same between your Apache and Hudson (that is, you can't run Hudson on http://localhost:8081/ci and have it exposed at http://localhost:80/hudson)

The ProxyRequests Off prevents Apache from functioning as a forward proxy server (except for ProxyPass), it is advised to include it unless the server should function as a proxy.

======================

http://community.webfaction.com/questions/4081/how-do-i-restart-apache-so-that-htaccess-is-reread-on-a-static-with-htaccess-app

RewriteEngine onRewriteCond %{REQUEST_URI} !^/Concentration/RewriteRule ^(.*)$ /Concentration/$1 [P,L]
 


Tag Cloud