Giter Site home page Giter Site logo

varnish-fwd's Introduction

Varnish forwarder

Transparently forwards all requests to multiple Varnish cache servers. Has an option to get the servers' IP addresses from AWS ECS given a cluster and service names.

Build and run

$ go mod download
$ go build -o main .
$ FWD_PROVIDER=static FWD_BACKENDS=http://127.0.0.1:3000,http://127.0.0.1:3001 ./main

In two other terminals launch the two example backends by running:

$ npx http-echo-server 3000

and

$ npx http-echo-server 3001

Sending requests to http://localhost:6081/test will result in the following output.

$ curl -v -X BAN http://localhost:6081/test
*   Trying 127.0.0.1:6081...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 6081 (#0)
> BAN /test HTTP/1.1
> Host: localhost:6081
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 18 Oct 2021 16:08:44 GMT
< Content-Length: 22
< Content-Type: text/plain; charset=utf-8
<
{"statuses":[200,200]}

Docker

There's a Dockerfile which can be built and run as follows:

$ docker build -t varnish-fwd -f Dockerfile .
$ docker run --rm -it -p 6081:6081 -e FWD_PROVIDER=static -e FWD_BACKENDS=http://172.17.0.1:3000,http://172.17.0.1:3001 varnish-fwd

Environment variables

Variable Default Description
FWD_PORT 6081 Listen on this port
FWD_PROVIDER ecs The provider of backend URLs. Can be ecs, static or file
FWD_REFRESH_INTERVAL 5m The interval on which to refresh the backends from the provider. Set to "0" to disable refreshing. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". See more here
VARNISH_PORT 6081 (for ecs) Port to use for backends
VARNISH_SCHEME http (for ecs) Protocol to use for backends
CLUSTER_NAME (for ecs) Name of the ECS cluster
VARNISH_SERVICE_NAME (for ecs) Name of the ECS service which has the Varnish tasks
FWD_BACKENDS (for static) List of backend URLs separated by comma. E.g. http://localhost:3000,http://localhost:3001
FWD_BACKENDS_FILE (for file) Path to the file that contains list of backend URLs separated by comma. E.g. http://localhost:3000,http://localhost:3001
AWS_PROFILE (optional) the profile to use when making requests to AWS
AWS_IAM_AUTHENTICATOR_CACHE_FILE (optional) full path to the file where AWS session credentials will be cached

Sample Environment config string for GoLand build configuration

AWS_PROFILE=myprofile;AWS_IAM_AUTHENTICATOR_CACHE_FILE=.aws-credentials-cache;CLUSTER_NAME=staging;VARNISH_SERVICE_NAME=varnish;FWD_PROVIDER=static;FWD_BACKENDS=http://localhost:3000,http://localhost:3001;VARNISH_SCHEME=https;VARNISH_PORT=6081

You can launch a test HTTP echo server based on NodeJS as follows

$ npx http-echo-server 3000

varnish-fwd's People

Contributors

vstanchev avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.