old blog,

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

Izhar Firdaus Izhar Firdaus Follow Support Jul 26, 2012 · 1 min read
Virtual hosting on Grok (or Bluebream) - without a reverse proxy
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
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.

Howto

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

Afterward, edit your WSGI INI file, (eg: etc/deploy.ini.in), 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:main]
pipeline = rewrite accesslogging evalexception fanstatic grok

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

[filter:rewrite]
use = egg:WSGIRewrite
rulesets = examplesite-http examplesite-https

[wsgirewrite:examplesite-http]
cond1 = %{HTTP_HOST} ^www.example.com$
cond2 = %{HTTPS} off
rule1 = ^/(.*) app/++vh++http:www.example.com/++/$1

[wsgirewrite:examplesite-https]
cond1 = %{HTTP_HOST} ^www.example.com$
cond2 = %{HTTPS} on
rule1 = ^/(.*) app/++vh++https:www.example.com/++/$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.
Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.

Grok framework quickstart template for OpenShift using the DIY cartridge

Another OpenShift goodness for Zope developers. A quickstart template for the Grok framework! Grok is now deployable easily on opensh...

In old blog, Jul 25, 2012

« Previous Post

diazotheme.bootstrap 0.2 released

I have been using diazotheme.bootstrap for a number of community sites for quite a while now. It was originally developed around Nove...

In old blog, Jul 27, 2012

Next Post »