Skip to content

mefellows/nginx-docker-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Domain Router

An example Nginx router setup, using Docker, complete with integration tests and resilience testing using Muxy.

TOC

Setup

Install & Setup Docker

  • Install Docker and Docker Machine
  • Build and run the image
docker-compose build && docker-compose up

This should spin up Nginx, DNSMasq and a test API (echo server). You can now hit the API at curl -v -H"Host: api.foo.com" <dockerhost>:8001/header/host. Note that we have to pass through the host header with the request.

Testing

Integration test suite for Nginx.

Running Tests

./scripts/run-tests.sh          # Run all tests
./scripts/run-tests integration # Run just the integration tests

Test Setup

To be able to run the Nginx router locally, and also to be able to test the configuration, we use dnsmasq in conjunction with Docker Compose.

Nginx is then configured to use dnsmasq for host resolution, allowing us to replace real systems with a Mock Service by creating host entries in the dnsmasq container. This works nicely in Production, where we don't create any host entries so the real services are resolved instead.

The components of the integration test are:

  • Nginx
  • dnsmasq - hijacks the real domain names, instructing Nginx to send traffic to our Mock Server so that we can test production configuration
  • Mock Server
  • Test Case container issuing requests against the Nginx instance

This can be visually represented as:

[Test Container] <- (issues tests to) -> [Nginx Container] <- (proxies) -> [Mock API]
                                                 ||        <- (proxies) -> [Backup API]   
                                                 ||
                                    (resolves DNS queries from)
                                                 \/
                                             [Dnsmasq]

About

Example Nginx setup using Docker, with integration tests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published