Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,31 @@ Build the following containers (follow each link for instructions):

`$ docker run -d -p 80:80 --name nginx-rp --volumes-from rp-data justadam/nginx-rp`

This gives us a nginx with a reverse proxy configuration (this file can be found at [docker-gen/templates/nginx.tmpl](docker-gen/templates/nginx.tmpl). The file will be updated by docker-gen each time a container stop or starts.
This gives us a nginx with a reverse proxy configuration (this file can be found at [docker-gen/templates/nginx.tmpl](docker-gen/templates/nginx.tmpl). The file will be updated by docker-gen each time a container stops or starts.

Now we need a container to serve some content; this could be anything (apache, nginx, your own webserver), but we will be using a static content site generator named hugo, which also comes with its own webserver.
Each container which is to sit behind the reverse proxy needs to set an environment variable called VHOST, which is the URL it will be serving content on.

### Start hugo

`$ docker run -d --name hugo -e VHOST=www.before.no -v $(pwd):/content justadam/hugo:0.12`

Testing
=======

Nginx-rp looks at all web requests coming in, and routes to different containers based on the `Host` HTTP header sent by a web browser. In this way a single front end can automatically route between different sub-webservers.

For testing, we need to pass our own `Host` header. Using boot2docker on OSX, this is:

curl -i --header 'Host: example.com' $(boot2docker ip 2> /dev/null)

The `example.com` matches `VHOST=example.com` in the top-level `fig.yml` file, therefore Nginx-rp routes the request to the `hello` Docker container. This container receives the request, and responds:

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 21 Jan 2015 14:33:16 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive

hello world
5 changes: 5 additions & 0 deletions fig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ hugo:
- ../websites/before.no/:/content
environment:
- VHOST=www.before.no
hello:
build: hello
environment:
- PORT=1234
- VHOST=example.com
8 changes: 8 additions & 0 deletions hello/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:2.7

ENV PYTHONUNBUFFERED 1

ADD hello.py /
CMD python /hello.py hello world

EXPOSE 1234
21 changes: 21 additions & 0 deletions hello/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import SimpleHTTPServer
import StringIO
import SocketServer
import os
import sys

PORT = int(os.environ['PORT'])
MESSAGE = ' '.join(sys.argv[1:])

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

def send_head(self):
self.send_response(200)
self.send_header("Content-type", 'text/plain')
self.end_headers()
return StringIO.StringIO(MESSAGE)

httpd = SocketServer.TCPServer(("", PORT), MyHandler)

print "serving at port", PORT
httpd.serve_forever()