|
| 1 | +### Reverse Proxy |
| 2 | + |
| 3 | +#### Traefik |
| 4 | + |
| 5 | +Take a look at the [traefik](https://github.com/traefik/traefik) implementation: |
| 6 | + |
| 7 | +```yaml |
| 8 | +services: |
| 9 | + secured-signal: |
| 10 | + image: ghcr.io/codeshelldev/secured-signal-api:latest |
| 11 | + container_name: secured-signal |
| 12 | + environment: |
| 13 | + API__URL: http://signal-api:8080 |
| 14 | + SETTINGS__VARIABLES__RECIPIENTS: |
| 15 | + '[+123400002,+123400003,+123400004]' |
| 16 | + SETTINGS__VARIABLES__NUMBER: "+123400001" |
| 17 | + API__TOKENS: '[LOOOOOONG_STRING]' |
| 18 | + labels: |
| 19 | + - traefik.enable=true |
| 20 | + - traefik.http.routers.signal-api.rule=Host(`signal-api.mydomain.com`) |
| 21 | + - traefik.http.routers.signal-api.entrypoints=websecure |
| 22 | + - traefik.http.routers.signal-api.tls=true |
| 23 | + - traefik.http.routers.signal-api.tls.certresolver=cloudflare |
| 24 | + - traefik.http.routers.signal-api.service=signal-api-svc |
| 25 | + - traefik.http.services.signal-api-svc.loadbalancer.server.port=8880 |
| 26 | + - traefik.docker.network=proxy |
| 27 | + restart: unless-stopped |
| 28 | + networks: |
| 29 | + proxy: |
| 30 | + backend: |
| 31 | + aliases: |
| 32 | + - secured-signal-api |
| 33 | + |
| 34 | +networks: |
| 35 | + backend: |
| 36 | + proxy: |
| 37 | + external: true |
| 38 | +``` |
| 39 | +
|
| 40 | +#### NGINX Proxy |
| 41 | +
|
| 42 | +This is the [NGINX](https://github.com/nginx/nginx) `docker-compose.yaml` file: |
| 43 | + |
| 44 | +```yaml |
| 45 | +services: |
| 46 | + secured-signal: |
| 47 | + image: ghcr.io/codeshelldev/secured-signal-api:latest |
| 48 | + container_name: secured-signal-api |
| 49 | + environment: |
| 50 | + API__URL: http://signal-api:8080 |
| 51 | + SETTINGS__VARIABLES__RECIPIENTS: "[+123400002,+123400003,+123400004]" |
| 52 | + SETTINGS__VARIABLES__NUMBER: "+123400001" |
| 53 | + API__TOKENS: "[LOOOOOONG_STRING]" |
| 54 | + restart: unless-stopped |
| 55 | + networks: |
| 56 | + backend: |
| 57 | + aliases: |
| 58 | + - secured-signal-api |
| 59 | +
|
| 60 | + nginx: |
| 61 | + image: nginx:latest |
| 62 | + container_name: secured-signal-proxy |
| 63 | + volumes: |
| 64 | + - ./nginx.conf:/etc/nginx/conf.d/default.conf |
| 65 | + # Load SSL certificates: cert.key, cert.crt |
| 66 | + - ./certs:/etc/nginx/ssl |
| 67 | + ports: |
| 68 | + - "443:443" |
| 69 | + - "80:80" |
| 70 | + restart: unless-stopped |
| 71 | + networks: |
| 72 | + frontend: |
| 73 | + backend: |
| 74 | +
|
| 75 | +networks: |
| 76 | + backend: |
| 77 | + frontend: |
| 78 | +``` |
| 79 | + |
| 80 | +Create a `nginx.conf` file in the `docker-compose.yaml` folder and mount it to `etc/nginx/conf.d/default.conf`: |
| 81 | + |
| 82 | +```conf |
| 83 | +server { |
| 84 | + # Allow SSL on Port 443 |
| 85 | + listen 443 ssl; |
| 86 | +
|
| 87 | + # Add allowed hostnames which nginx should respond to |
| 88 | + # `_` for any |
| 89 | + server_name localhost; |
| 90 | + |
| 91 | + ssl_certificate /etc/nginx/ssl/cert.crt; |
| 92 | + ssl_certificate_key /etc/nginx/ssl/cert.key; |
| 93 | + |
| 94 | + location / { |
| 95 | + # Use whatever network alias you set in the docker-compose file |
| 96 | + proxy_pass http://secured-signal-api:8880; |
| 97 | + proxy_set_header Host $host; |
| 98 | + proxy_set_header X-Real-IP $remote_addr; |
| 99 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 100 | + proxy_set_header X-Forwarded-Host $host; |
| 101 | + proxy_set_header X-Fowarded-Proto $scheme; |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +# Redirect HTTP to HTTPs |
| 106 | +server { |
| 107 | + listen 80; |
| 108 | + server_name localhost; |
| 109 | + return 301 https://$host$request_uri; |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +Lastly add your `cert.key` and `cert.crt` into your `certs/` folder and mount it to `/etc/nginx/ssl`. |
0 commit comments