mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-21 05:21:03 +08:00
bafc30bec6
"#if FOO" still works with simple -DFOO, but gives more flexibility. Specifically, if user expressed no preference (FOO is not defined), we can apply reasonable defaults (this is the legitimate use of ifdef). In short, from now on, please use #if MG_ENABLE_FOO instead of #ifdef MG_ENABLE_FOO Since we are all used to #ifdef, this change also adds a precommit check to police this. Specifically, in *.h and *.c files that are Copyright Cesanta, "ifdef" and "if defined()" are not allowed to be used with macros that contain ENABLE or DISABLE, unless the like also contains "ifdef-ok". Hence, if you are sure you want to use ifdef, use this: #ifdef MG_ENABLE_FOO /* ifdef-ok */ PUBLISHED_FROM=9be829448f53cff575d6cae8b9945fb12531c15a |
||
---|---|---|
.. | ||
Dockerfile | ||
load_balancer.c | ||
Makefile | ||
README.md | ||
unit_test.sh |
Mongoose-based HTTP load balancer
Configuration
Load balancer is configured with command-line flags.
Global flags
-p port
– TCP port to listen on. Default: 8000.-l log_file
– path to the log file. Default: none.-s ssl_cert
– path to SSL certificate. Default: none.
Backend configuration
Main flag is -b uri_prefix host_port
– it adds a new backend for a given
URI prefix. Example: -b /stuff/ 127.0.0.1:8080
will route all requests that
start with '/stuff/' to a backend at port 8080 on localhost. There is a special
syntax for uri_prefix
that allows you to change the URIs that get passed to
backends:
-b /stuff/=/ 127.0.0.1:8080
– for '/stuff/thing' backend will see '/thing'.-b /stuff/=/other/ 127.0.0.1:8080
– '/stuff/thing' => '/other/thing'.
Also there are few per-backend flags that can be placed before -b
and apply
only to the next backend:
-r
– instead of proxying requests load balancer will reply with 302 redirect.-v vhost
– match not only URI prefix but 'Host:' header as well.
Example
load_balancer -s path/to/cert.pem \
-v example.com -b /site/=/ 127.0.0.1:8080 \
-b /static/ 127.0.0.1:8081 \
-b /static/ 127.0.0.1:8082
In this example requests to 'example.com/site/' will be forwarded to the backend on port 8080 with '/site' prefix stripped off and requests to '/static/' on any virtual host will be balanced in round-robin fashion between backends on ports 8081 and 8082.