Skip to content

Docker image running an HTTP server that redirects all incoming requests based on it's given configuration

License

Notifications You must be signed in to change notification settings

WyriHaximusNet/docker-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker redirect image

Github Actions Docker hub Docker hub Docker hub Buy Phil a tree

Docker image running an HTTP server that redirects all incoming requests based on it's given configuration.

Why

To improve my personal knowledge of programming languages I'm aiming to create the same HTTP server that will redirect incoming requests according to the given config in a different language each month of 2020.

As I'm moving my personal projects onto kubernetes I needed a way to redirect DOMAIN.TLD to www.DOMAIN.TLD. Now kubernetes already has support for this through nginx.ingress.kubernetes.io/from-to-www-redirect. But since this is such a small isolated feature it's perfect to try out new languages in and maybe go beyond this in some of them. After all this is a learning exercise for me. One with strict tests set up using k6 to ensure the same behavior across languages.

Provided tags

  • random - Each time when the images are build a random image is selected and build.
  • reactphp - Using ReactPHP (January 2020)
  • nodejs - Using NodeJS (February 2020)

Configuration

These images comes with 3 mandatory configuration options:

  • defaultFallbackTarget - Requests not matching other rules will be redirected here
  • buildin.wwwToNonWww - Redirects www.DOMAIN.TLD to DOMAIN.TLD; mutually exclusive with buildin.nonWwwToWww
  • buildin.nonWwwToWww - Redirects DOMAIN.TLD to www.DOMAIN.TLD; mutually exclusive with buildin.wwwToNonWww

There are also two optional configuration options for custom hostname based redirection, and HTTPS enforcement:

  • hosts - from -> to based key value mapping
  • enforceHttps - boolean for enforcing redirecting to HTTPS or not, defaults to false

Full configuration example:

defaultFallbackTarget: https://blog.wyrihaximus.net/
enforceHttps: true
buildin:
  wwwToNonWww: false
  nonWwwToWww: true
hosts:
  ceesjankiewiet.nl: wyrihaximus.net
  wyrimaps.com: wyrimaps.net

Keep in mind that the configuration options are executed in the following order:

  1. hosts
  2. buildin.wwwToNonWww or buildin.nonWwwToWww
  3. defaultFallbackTarget

Usage

The image can be start from the command line with the following command:

docker run -d --rm -v /path/to/config.yaml:/etc/redirect/config.yaml wyrihaximusnet/redirect:random

Once started the HTTP server is available at port 7132 for requests.

Ports

These docker images expose two ports:

  • 7132 - The world facing HTTP server doing the redirects.
  • 7133 - Internal metrics server.

Both servers don't check for routes routes and either serve what they are build to serve.

Metrics

These images export the following metric in Prometheus format:

  • http_requests_total - The total amount of requests made, this metric comes with the following tags: fromHost (the host the request is made to), method (the HTTP method used to make the request), and toHost (the host the client is redirected to).

Different images may export different additional metrics but the one above and it's tags are guaranteed to be in all images.

License

You're free to use this docker image as it's provided under the MIT license, but if it makes it to your production environment I would highly appreciate you buying the world a tree. It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats. As I don't have my own offset earth forrest you can buy trees at for Phil's forest here offset.earth/philsturgeon.

About

Docker image running an HTTP server that redirects all incoming requests based on it's given configuration

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •