Giter Club home page Giter Club logo

bilziv's Introduction

Simple Web App using GHA & docker

Docker Compose

Simple web app (simple index.html) using Nginx with HAProxy as Load balancer for at least two backend serves

Generate self-signed certs for HAproxy:

openssl req -x509 -newkey rsa:4096 -sha256 \
                  -days 3650 -nodes \
                  -keyout server.key \
                  -out server.crt \
                  -subj "/CN=localhost" \
                  -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"

Save them as ssl.pem

cat server.crt server.key  > haproxy/ssl/ssl.pem

Start env:

docker-compose up -d

Check env:

Example:

docker ps
CONTAINER ID   IMAGE                            COMMAND                  CREATED          STATUS          PORTS                                   NAMES
7e84c16fb380   dariusza/bilziv-haproxy:latest   "docker-entrypoint.s…"   15 minutes ago   Up 15 minutes   0.0.0.0:443->443/tcp, :::443->443/tcp   bilziv_haproxy_1
73974e42953a   dariusza/bilziv-www:latest       "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp                                  bilziv_web1_1
c068c870d617   dariusza/bilziv-www:latest       "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp                                  bilziv_web2_1

TEST

curl -vk https://localhost:443/

Output:

{ "msg": " Hello World!" }

bilziv's People

Contributors

daro1337 avatar

bilziv's Issues

Project will not start if changes are not applied

In the docker-compose.yaml image: section needs to correspond to a valid image from Docker Hub.

should be

image: daro1337/bilziv-www:latest

haproxy.cfg

global and defaults cannot be left empty. HAProxy will not load due to missing timeouts. See example Error Log below

dariusz-adamczyk-haproxy-1  | [NOTICE]   (1) : haproxy version is 2.6.2-16a3646
dariusz-adamczyk-haproxy-1  | [WARNING]  (1) : config : missing timeouts for frontend 'web-front'.
dariusz-adamczyk-haproxy-1  |    | While not properly invalid, you will certainly encounter various problems
dariusz-adamczyk-haproxy-1  |    | with such a configuration. To fix this, please ensure that all following
dariusz-adamczyk-haproxy-1  |    | timeouts are set to a non-zero value: 'client', 'connect', 'server'.
dariusz-adamczyk-haproxy-1  | [WARNING]  (1) : config : missing timeouts for backend 'web-front'.
dariusz-adamczyk-haproxy-1  |    | While not properly invalid, you will certainly encounter various problems
dariusz-adamczyk-haproxy-1  |    | with such a configuration. To fix this, please ensure that all following
dariusz-adamczyk-haproxy-1  |    | timeouts are set to a non-zero value: 'client', 'connect', 'server'.
dariusz-adamczyk-haproxy-1  | [ALERT]    (1) : config : Proxy 'web-front': no SSL certificate specified for bind '*:443' at [/usr/local/etc/haproxy/haproxy.cfg:7] (use 'crt').
dariusz-adamczyk-haproxy-1  | [ALERT]    (1) : config : Fatal errors found in configuration.

bind to port 80 is not necessary since docker-compose.yaml is configured to respond and direct traffic via 443 only.

After changing the haproxy.cfg to as on example below project will start.

global
    stats socket /tmp/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
    log stdout format raw local0 info

defaults
    mode http
    timeout client 10s
    timeout connect 5s
    timeout server 10s
    timeout http-request 10s
    log global

frontend web-front
    # bind *:80
    bind :443 ssl crt /usr/local/etc/haproxy/ssl/ssl.pem
    acl https ssl_fc
    http-request set-header X-Forwarded-Proto http  if !https
    http-request set-header X-Forwarded-Proto https if https
    mode http
    default_backend web-front

backend web-front
    mode http
    balance roundrobin
    server srv1 web1:80
    server srv2 web2:80

Side note:

The creation of the SSL certificate could be a simple BASH script.

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.