Giter Site home page Giter Site logo

hw-go-server's Introduction

Trafik Reverse Proxy with Let's Encrypt and Docker Services

This repository provides a simple example on how to use Trafik as a reverse proxy for Docker services, securing your services with SSL certificates from Let's Encrypt. In this setup, we run two instances of a simple "Hello, World!" GoLang web server, each bound to a different subdomain.

Prerequisites

Ensure that you have Docker and Docker Compose installed on your machine. You also need a registered domain name, as we'll be issuing SSL certificates for specific subdomains.

Setup

  1. Clone the repository:

    git clone https://github.com/sekulicd/hw-go-server.git
  2. Modify the docker-compose.yml file:

    • Replace [email protected] with your email address
    • Replace hw1.dusansekulic.me and hw2.dusansekulic.me with your desired subdomains
  3. Run Docker Compose:

    docker-compose up -d
  4. Start new service(Optional):

    docker run -d \
      --network=web \
      --name=hw3 \
      -p 8083:8080 \
      --label "traefik.enable=true" \
      --label 'traefik.http.routers.hw3.rule=Host(`hw3.dusansekulic.me`)' \
      --label "traefik.http.routers.hw3.entrypoints=websecure" \
      --label "traefik.http.routers.hw3.tls.certresolver=myresolver" \
      {WEB_IMAGE}

Usage

After the Docker Compose setup has finished, you can access your services through your specified subdomains, they should be served over HTTPS, thanks to the Let's Encrypt certificates issued by Trafik.

Architecture

The traefik service is our entrypoint and routes incoming requests to the appropriate service based on the request's Host header.

It's configured to automatically generate Let's Encrypt SSL certificates for our specified subdomains. The generated certificates are stored in the ./letsencrypt/acme.json file.

The hw1 and hw2 services are simple "Hello, World!" GoLang web servers. They're each built from the Dockerfile included in the repository and are assigned a unique subdomain through Docker Compose labels.

Notes

Remember, the Let's Encrypt CA server used here is the staging server. For production, you should use the production server https://acme-v02.api.letsencrypt.org/directory.

Also, note that the external network 'web' is required to be pre-created before running the docker-compose up -d command. If it doesn't exist, create it with docker network create web.

hw-go-server's People

Contributors

sekulicd avatar

Watchers

 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.