by Devin Yang
(This article was automatically translated.)

Published - 5 years ago ( Updated - 5 years ago )

Raspberry is very cheap and has quite a lot of applications, for example, some people use it as a Wifi router,
For game consoles, monitors and many other IoT-related applications, I use it as a HAProxy.

Long story short, because I have an old Windows server, he runs old versions of PHP and Apache, and can't set up HTTPS certificates, so I want to say
Help through HAProxy. Let this old server also have https URL,
So to share my docker-compose.yml configuration.

Required knowledge:
This article assumes that you already know the relevant settings of haproxy.
If you do not know how to install docker and docker-compose on your Raspberry Pi, please refer to the following website:
https://www.ccc.tc/article/install -docker-and-docker-compose-on-raspberrypi

The settings for docker-compose are as follows:
The following is my docker-compose.yml settings
version: '3.6'
services:
 haproxy:
  network_mode: host
  image: haproxy
  restart: always
  environment:
    backend_server: 192.168.1.100
  volumes:
    - ./cert.pem:/etc/ssl/cert.pem
    - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
There are several important settings here
1. restart: always
When it is successfully started, it will automatically start docker-compose again next time it is restarted, and there is no need to enter the Raspberry to command docker-compose up.
Regarding the restart policy (restart policy), at least 10 seconds after a successful startup, it means a successful startup, and it will automatically restart at the next restart.

2. network_mode: host
This is a network mode that can only be set by Linux, which can directly bind the port bound to the container to the host
(The so-called host refers to Raspberry, so it is tied to the eth0 network card of the Raspberry Pi),
So I can import the incoming traffic from Raspberry directly to the host (backend_server) of another entity.

3. environment
We can set the location of backend_server in the environment,
You can use this setting in the HAProxy configuration file.

Four, volumes
Mounted the credentials and haproxy.cfg settings.

Basic knowledge about basic instructions of docker-compose:
We can create a haproxy folder, put the docker-compose.yml file and certificate, and the haproxy configuration file.
Then, execute
docker-compose up -d
You can start it.
stop is:
docker-compose down
If we want to view the log, we can execute
docker-compose logs -f


Here is a simple diagram:
The blue line is the SSL-encrypted URL. After the traffic enters HAProxy, the traffic is directed to the backend (backend_server), an unencrypted URL.


Supplement
This article assumes that you have already understood the various settings of haproxy.cfg, and will not explain it. Please consult Google teacher yourself.
Some information about the fragments related to this docker-compose is for reference.
server web ${backend_server}:80 check cookie s1

# or
backend mysql
   mode tcp
   server database ${backend_server}:3306
The variable above, ${backend_server} is the 192.168.1.100 we set in docker-compose.yml.





 

Tags: docker

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


docker, goaccess, config

phpenv actual combat GoAccess is real website analysis (docker version)

Before I start, let me say that GoAccess can also generate static data as long as you have a log, because I think the real-time feeling is more dazzling, so this article will focus on the part of GoAccess real-time display. Although Google Analytics (GA) is very useful, it is also very good to try another GA. For example, you want to know which browsers website users use to visit the website.

docker laravel

Chatting about D-Laravel's console commands

D-Laravel's console command allows us to quickly understand what he executes. How is it executed if docker-compose is used? Let's see.

d-laravel, docker, laravel, docker-compose

D-Laravel v1.0.0 release change description

In order to allow the container to be used more flexibly, D-Laravel has released version v1.0.0, which is not backward compatible. https://github.com/DevinY/dlaravel/releases/tag/v1.0.0 If you are using before v1.0.0, you need to modify the .env file of the Laravel project, change DB_HOST=127.0.0.1 to DB_HOST=db If you have a custom docker-compose-custom.yml file....more