uberproxy v0.5.4
UberProxy
In the cloud era we need smart proxies.
Features
- Highly configurable
- Provides a RESTful interface to add and remove workers, SSL domains, etc.
- Easy to extend.
- Write plugins in Javascript!
- Everything is a plugin internally
- Fast (NodeJS is neat handling lots of I/O)
- Efficient uploads
- The proxy buffer to disk a file upload
- When it's ready it forwards to the worker
- The Proxy deal much better with slow connections
- Throttle connections to workers (by default 20 per worker)
- SSL support
- URL sanitization
//foobar///will be rewrite to/foobarbefore forwarding the app
- The workers are in control of everything:
- Rewrite hostname
- Rewrite URL
- Expose URL (with regular expressions) they can work
- If a worker can serve
^/(foo|bar)/.+, any other request will generate a404 Error pagein the proxy itself.
- If a worker can serve
- They can choose which plugins to use (Global plugins may apply any ways)
Some concepts
- Proxy: It's a webserver which is in the between a client and an application
- Worker: It's a webserver, where our application is hosted.
Why a proxy?
Having a proxy makes really easy to scale up or down our applications in a matter of seconds. UberProxy makes it possible to add and remove more workers to your application.
Installation
npm install -g uberproxyConfiguration
To create a new configuration you need to run the following command
# Create a secret token
uberproxy setupThat will generate a config.yml (you can override that with -c config.json) that would look like this:
ssl:
port: 443
certs: /var/tmp/uberproxy/https-certs
dynamic: /var/tmp/uberproxy/dynamic.yml
cluster: 4
port: 80
secret: 8e0c5e97f91e1a8dde85702ffadff48e8488fda46c457712920aa835dabe25c8In order to run the server you should execute this command:
uberproxy server [-c|--config config.yml] [-w|--worker workers_count] [-p|--http-port 80] [-s|--https-port 443]You can override config variables:
UBERPROXY_CONFIGoverrides config filenameUBERPROXY_DYNAMICoverrides dynamic config filename -dynamicsection ofconfig.ymlUBERPROXY_SSL_CERTSoverrides ssl path -ssl.certssection ofconfig.ymlUBERPROXY_SECREToverrides secret -secretsection ofconfig.ymlUBERPROXY_CLUSTERoverrides workers count -clustersection ofconfig.yml
If you run uberproxy with empty config it will be initialized with default values just like you prepared next config:
ssl:
port: 443
certs: /config/ssl
dynamic: /config/dynamic.yml
cluster: 4
port: 80Config's secret key is mandatory and haven't default value.
So if you want to run uberproxy with empty config - you need to pass secret via environment variable:
UBERPROXY_SECRET=123 uberproxy -c empty.ymlOtherwise error will be raised.
Parts
- ssl
- port: What port should the Https-Proxy listen to?
- certs: What directory should be used to store the certs files?
- dynamic: A file (
YAMLorJSON) where the dynamic configurations are stored. - cluster: How many workers should it use? Ideally it should the same number of CPUs available on the erver
- port: What port should the Http-proxy listen to?
- secret: A secret token used for the dynamic configuration
Running
node index.jsYou may need it to run as sudo, by default it tries to open 80 and 443 (port which usually requires super user permissions).
Then open http://127.0.0.1/. You would see a Not Found page, that is because the proxy doesn't have any worker configured yet.
Adding workers
To add a plugin you can see the PHP Client, just make sure the secrets are the same.
It's also possible to define a worker on the config file. If you're using YAML it would look like this:
workers:
-
worker: 'localhost:3333'
hostname:
- domain2.foobar.net
maxreq: 20That's it, all requests for domain2.foobar.net will be forwarded to localhost:3333.
Docker
Please refer to DOCKER.md for details on how to build a docker image, or to use Uberproxy directly from the Docker Hub.
TODO
- More documentation
- Config to register apps
- Protocol
- More examples on plugins
- Cache plugins
- ZLib
- Code style
- Add .editorconfig
- Add .jscsrc