Skip to content

Commit

Permalink
Added examples, improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kyr0 committed Dec 28, 2012
1 parent a841de2 commit bfb8609
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
61 changes: 44 additions & 17 deletions README.md
@@ -1,8 +1,8 @@
# A dead simple HTTP vhost proxy routing / port sharing implementation for node.js

This project implements a dead simple HTTP multi domain name / IP /
directory vhost port forwarding router proxy using the http-proxy module.
It shows the power of node.js by being implemented in less than 50 lines of code.
This project implements a simple HTTP multi domain name / IP / directory vhost port forwarding router/proxy
using the http-proxy module. It does what a reverse proxy does for you combined with some mod_rewrite feature support.
It also shows the power of node.js by being implemented in less than 100 lines of code.

## Prerequisites

Expand All @@ -20,40 +20,67 @@ Make sure:

## Configuring

A valid configuration file for port-vhoster is written in JSON notation and
contains 3 sections:
A valid configuration file for port-vhoster is written in JSON notation as a single object that should provide
three key/value pairs:

- description = Description to log to the TTY
- port = Source port to listen to. This is the port you want to enable port sharing for (e.g. 80)
- vhosts = An object containing key ($ip OR $domain/port) and a value (target $ip:$port/$path)
- description (String) = Description, printed to the terminal on startup.
- port (Number) = Source port (share port) to listen to (e.g. 80).
- vhosts (Object) = Key ($ip OR $domain/port) / value (target $ip:$port/$path)-pairs of vhost-configurations.

## Configuration example

The following configuration is a simple routing example. You can add more vhosts to the object
and register more complex routings (domain name, ip, path) too:
The following configuration is a simple routing example. You can add more vhosts to the config object too:

```
{
"description": "For example routing all HTTP requests of port 8100 to localhost:8080...",
"port": 8100,
"description": "Routing with port sharing on port 80 (HTTP) for some domains and paths...",
"port": 80,
"vhosts": {
"localhost": "127.0.0.1:8080"
"www.aron-homberg.de": "127.0.0.1:8081",
"aron-homberg.de": "127.0.0.1:8081",
"example.com/downloads": "10.0.0.1:8080",
"example.com/uploads": "10.0.0.2:8080/master/golive/upload"
}
}
```

By default you should save the config as plain text file called ```port-vhoster.json```.
Take a look at the [examples](https://github.com/kyr0/port-vhoster/tree/master/examples) directory for more inspiration.

## Running the port sharing proxy

Dead simple, just call node to run ```port-vhoster.js``` optionally name an alternative config file path:
By default, ```port-vhoster``` searches for a config file called ```port-vhoster.json``` in current working directory.
If you want to use a different name, run ```port-vhoster``` with the optional argument to name the config file:

```
[sudo] port-vhoster [alternative-config-file.json]
[sudo] port-vhoster [$alternative-config-file.json]
```

You will need super user permissions if you try the listen to (share) ports below 1024 (e.g. port 80).
You may need super-user permissions if you want ```port-vhoster``` to listen to a port below 1024 (e.g. port 80).

## Logging and server mode

If you're on a Unix/Linux/Mac OS X system you can run port-vhoster in server mode easily:

Starting (e.g. ```start-vhoster.sh``` - don't forget to: ```chmod +x start-vhoster.sh```!):

```
#!/bin/sh
echo "Starting port-vhoster..."
nohup port-vhoster > port-vhoster.out 2> port-vhoster.err < /dev/null &
```

Stopping (e.g. ```stop-vhoster.sh``` - don't forget to: ```chmod +x stop-vhoster.sh```!):

```
#!/bin/sh
echo "Stopping port-vhoster..."
kill $(ps aux | grep '[port]-vhoster' | awk '{print $2}')
```

For sure, server mode and logging may also be possible on Microsoft Windows platform but that's currently untested.
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/multidomain_port_80.json
@@ -0,0 +1,8 @@
{
"description": "Shadow-routing HTTP traffic of multiple domains using one shared port (80)...",
"port": 80,
"vhosts": {
"www.aron-homberg.de": "127.0.0.1:8081",
"aron-homberg.de": "127.0.0.1:8081"
}
}
7 changes: 7 additions & 0 deletions examples/subdirectory_rewrite_routing.json
@@ -0,0 +1,7 @@
{
"description": "Routing requests from one domain (port 80), path /downloads to path / on localhost:8082...",
"port": 80,
"vhosts": {
"www.aron-homberg.de/downloads": "127.0.0.1:8082"
}
}

0 comments on commit bfb8609

Please sign in to comment.