GithubHelp home page GithubHelp logo

olivere / sslserve Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 6 KB

Go service, scaled and proxied behind NGINX, using Docker Compose.

Dockerfile 1.43% Makefile 4.63% Go 93.94%
go golang docker docker-compose nginx scaleable proxy ssl

sslserve's Introduction

Scaled service on Docker via SSL

This repository is an example of using a Go service behind an NGINX webserver that is accessible via HTTPS/SSL on https://localhost:443. It also illustrates how to scale a service in local development with Docker Compose.

Getting started

First, you need to create an SSL certificate as described on Let's Encrypt for localhost:443.

openssl req -x509 -out etc/nginx/localhost.crt -keyout etc/nginx/localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

Next, follow these steps:

  1. make build will create the Go binary ./service.
  2. docker-compose up --build -d will download, build, and start the application.
  3. Open https://localhost:443 and accept the warning the browser will give you. You should read the current time every time the browser refreshes the page.

By default, only one instance of the service is running. So if you curl https://localhost:443 multiple times, it will also print the same hostname.

But you can scale multiple instances of the service by invoking e.g.:

docker-compose up --scale service=3

That will create 3 identical instances of the service which NGINX will proxy to all of them.

When you now curl https://localhost:443 multiple times, and it should print different hostnames. Notice that it may take up to 30 seconds (as defined in the NGINX configuration file) for the DNS resolver to purge its cache.

This works by using the default DNS resolver that Docker creates by default on 127.0.0.11.

License

MIT.

sslserve's People

Contributors

olivere avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

shivkumarsingh7

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.