Grok, Virtual Hosting and NginxΒΆ
Author: | Sebastian Ware |
---|
Configuring the super fast and lightweight Nginx HTTP server to support virtual hosting.
Zope 3 and thus Grok supports virtual hosting straight out of the box. The super fast and lightweight Nginx HTTP server does this too. In fact, it is so easy to congfigure even a caveman could do it... so I did.
This is a stripped down version of [nginx.conf] with only the relevant statements included. Add these in the appropriate places to the default nginx.conf and you will be cooking in no time.
1 2 3 4 5 6 7 8 9 10 11 12 | http {
upstream mygrokinstance {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://mygrokinstance/grok_application_name/++vh++http:www.example.com:80/++;
}
}
}
|
Explanation:
- 2-4:
- Defining a backend server mygrokinstance. This also allows me to add simple load-balancing (round-robin and client IP) by adding an extra line for each server.
- 5-11:
- Server directives...
- 6:
- The port that Nginx listens to.
- 7:
- The domain name used to access the application.
- 8-10:
- The rewrite rule.
- 8:
location /
corresponds to anything.location /application
would equal anything starting withwww.example.com/application
- 9:
The rewrite rule, where:
mygrokinstance
is the backend server that we defined on row 3-5grok_application_name/
is the application name since I don’t want to have to include it in the URLshttp:www.example.com:80/
tells zope to generate the URLs without the application name
More on Nginx:
Virtual hosting in Zope 3:
The Nginx upstream command: