Grok and Apache

Author:Matthias

Configuring the Apache HTTP server with grok.

There are two approaches to make your Grok application work with Apache: either through mod_wsgi or by using mod_rewrite and mod_proxy.

If you choose the mod_wsgi way then your application will run directly under Apache.

If you choose the mod_rewrite way, you will run your application as a paster server (probably the same server you are currently using for development). Then you make Apache a proxy to the paster server. This means Apache takes any incoming requests and forwards them to the paster server running on localhost. The results from paster are then returned to Apache which returns them to the browser. This way paster is not exposed directly to the internet.

This document will cover different aspects of integration between Grok and Apache. If there are missing spots, please post on the Grok mailing list so we can fill them in.

Virtual hosting (mod_wsgi)

If you want to just get started with grok and mod_wsgi you don’t need any virtual hosting setup. E.g. you want to be able to access example.com/grokui . However if you want something like example.com to serve a certain grok application of yours, you’ll have to setup virtual hosting.

Setting up virtual hosting for using Grok, Apache and mod_wsgi, Apache configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 <VirtualHost *:80>
     Servername example.com
     RewriteEngine on

     # Possible values include: debug, info, notice, warn, error, crit,
     # alert, emerg.
     #LogLevel warn
     #ErrorLog /home/myuser/example.site/log/error.log
     #CustomLog /home/sites/example.site/log/access.log combined


     # An example setup with two grok applications
     # Both are served from a dedicated apache daemon process. Both sites use separate python
     #  interpreters. They are completely isolated from each other

     ## Application 1 ##
     # Here: served under example.com/apps/fritz
     WSGIDaemonProcess example-fritz user=www-data threads=2
     RewriteRule ^/apps/fritz(.*) /apps/fritz/++vh++http:example.com:80/apps/fritz/++$1 [L,PT]
     Alias /apps/fritz /home/myuser/example.site/apps/fritz/parts/wsgi_app/wsgi/
     <Directory /home/myuser/example.site/apps/fritz/parts/wsgi_app>
            WSGIApplicationGroup example-fritz
            WSGIProcessGroup example-fritz
            WSGIPassAuthorization On
            SetHandler wsgi-script
            Options ExecCGI FollowSymLinks
            Order allow,deny
            Allow from all
     </Directory>


     ## Application 2 ##
     # Here: served under example.com/apps/heinz
     WSGIDaemonProcess example-heinz user=www-data threads=2
     RewriteRule ^/apps/heinz(.*) /apps/heinz/++vh++http:example.com:80/apps/heinz/++$1 [L,PT]
     Alias /apps/heinz /home/myuser/example.site/apps/heinz/parts/wsgi_app/wsgi/
     <Directory /home/myuser/example.site/apps/heinz/parts/wsgi_app>
            WSGIApplicationGroup example-heinz
            WSGIProcessGroup example-heinz
            WSGIPassAuthorization On
            SetHandler wsgi-script
            Options ExecCGI FollowSymLinks
            Order allow,deny
            Allow from all
     </Directory>


 </VirtualHost>

Virtual hosting (mod_rewrite/mod_proxy)

Setting up virtual hosting for using Grok, Apache and mod_rewrite/mod_proxy and paster running on localhost:8080, Apache configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 <VirtualHost *:80>
     SSLDisable
     Servername example.com
     RewriteEngine on

     # Application: served under example.com/apps/fritz
     RewriteRule ^/apps/fritz(/?.*)  http://localhost:8080/apps/fritz/++vh++http:www.example.com:80/apps/fritz/++$1 [P,L]
     CustomLog /var/log/apache/example.com/access.log combined
     ErrorLog /var/log/apache/example.com/error.log
 </VirtualHost>

Virtual hosting (general)

Virtual hosting in Zope 3: