Virtual hosting on Grok (or Bluebream) - without a reverse proxy

When I was poking at creating the Grok template for OpenShift, I needed to add virtual hosting for the test application.

However, OpenShift's DIY cartridge does not allow me to modify the reverse proxy settings as they are automatically generated by the cartridge. Naturally, I had to find another way.

Grok virtual hosting with WSGIRewrite

WSGIRewrite is a WSGI middleware which provide a facility for mod_rewrite compatible rewrite rules for WSGI applications. Using this middleware, we can rewrite the URL to force virtual hosting on the application server.

Lets go straight to the meat, here is the howto.


The first step is of course, to add WSGIRewrite into your buildout. Edit and add 'WSGIRewrite' into the install_requires list, and re-run buildout.

Afterward, edit your WSGI INI file, (eg: etc/, and find a section called pipeline:main, and add rewrite as the first item in the pipeline. The section should appear like this now:

pipeline = rewrite accesslogging evalexception fanstatic grok

At the bottom of the file, add these lines. Replace examplesite with an identifier for the entry, replace app with your application ID, and replace with the virtual hosting domain:

use = egg:WSGIRewrite
rulesets = examplesite-http examplesite-https

cond1 = %{HTTP_HOST} ^$
cond2 = %{HTTPS} off
rule1 = ^/(.*) app/$1

cond1 = %{HTTP_HOST} ^$
cond2 = %{HTTPS} on
rule1 = ^/(.*) app/$1
Rerun buildout to regenerate your INI files, and start your paster/wsgi server. Access the server using the configured domain, and it should work.


Popular posts from this blog

Announcing PlatoCDP, a Plone distribution for enterprises.

Adding simple popup to Plone frontpage

Consolidated community site infrastructure on Plone