Skip to content

Commit c64de75

Browse files
committed
Add examples/
1 parent 99fc7e2 commit c64de75

File tree

40 files changed

+686
-0
lines changed

40 files changed

+686
-0
lines changed

examples/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Examples
2+
3+
4+
A Quick overview about available examples
5+
6+
| Complexity | Virtual Host | Backend | Description | Link |
7+
|------------|--------------|---------|-------------|------|
8+
| simple | Default | None | Serve static files | [default-vhost__static-files](default-vhost__static-files) |
9+
| simple | Default | NodsJS | Reverse Proxy to Node app | [default-vhost__reverse-proxy__node](default-vhost__reverse-proxy__node) |
10+
| simple | Default | Python | Reverse Proxy to Python app | [default-vhost__reverse-proxy__python](default-vhost__reverse-proxy__python) |
11+
| simple | Default | PHP-FPM | Serve PHP files | [default-vhost__php-fpm](default-vhost__php-fpm) |
12+
| medium | Default | PHP-FPM | Serve PHP files over HTTPS (SSL) | [default-vhost__php-fpm__ssl](default-vhost__php-fpm__ssl) |
13+
| complex | Mass vhost | PHP-FPM | Mass vhosting with auto-generated SSL for each host | [mass-vhost__php-fpm__ssl](mass-vhost__php-fpm__ssl) |
14+
| complex | Mass vhost | Multi | Mass vhosting with auto-generated SSL for each host (PHP-FPM and NodeJS reverse Proxy) | [mass-vhost__reverse-proxy__ssl/](mass-vhost__reverse-proxy__ssl/) |
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Example: PHP_FPM
2+
3+
Docker Compose example with a remote PHP-FPM server.
4+
5+
## Run
6+
```bash
7+
docker-compose up
8+
```
9+
10+
## View
11+
```bash
12+
curl http://localhost:8000
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
version: '2.3'
3+
4+
services:
5+
6+
# HTTPD Server
7+
httpd:
8+
image: devilbox/nginx-stable:alpine
9+
build:
10+
context: ../../Dockerfiles
11+
dockerfile: Dockerfile.alpine
12+
hostname: httpd
13+
environment:
14+
- NEW_UID=1000
15+
- NEW_GID=1000
16+
- MAIN_VHOST_BACKEND=conf:phpfpm:tcp:php:9000
17+
ports:
18+
- "8000:80"
19+
volumes:
20+
- ./www:/var/www/default/htdocs
21+
depends_on:
22+
- php
23+
24+
# PHP-FPM Server
25+
php:
26+
image: devilbox/php-fpm:8.2-base
27+
hostname: php
28+
environment:
29+
- NEW_UID=1000
30+
- NEW_GID=1000
31+
volumes:
32+
- ./www:/var/www/default/htdocs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
docker-compose build
8+
docker-compose up -d
9+
sleep 10
10+
11+
if ! curl http://localhost:8000 | grep '[OK]'; then
12+
docker-compose logs || true
13+
docker-compose stop || true
14+
docker-compose rm -f || true
15+
exit 1
16+
fi
17+
18+
docker-compose logs || true
19+
docker-compose stop || true
20+
docker-compose rm -f || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[OK]
2+
<h1>PHP version: <?php echo phpversion();?></h1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Example: PHP_FPM
2+
3+
Docker Compose example with a remote PHP-FPM server and serving HTTPS
4+
5+
## Run
6+
```bash
7+
docker-compose up
8+
```
9+
10+
## View
11+
```bash
12+
# HTTP
13+
curl http://localhost:8000
14+
15+
# HTTPS
16+
curl -k https://localhost:8443
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
version: '2.3'
3+
4+
services:
5+
6+
# HTTPD Server
7+
httpd:
8+
image: devilbox/nginx-stable:alpine
9+
build:
10+
context: ../../Dockerfiles
11+
dockerfile: Dockerfile.alpine
12+
hostname: httpd
13+
environment:
14+
- NEW_UID=1000
15+
- NEW_GID=1000
16+
- MAIN_VHOST_SSL_TYPE=both
17+
- MAIN_VHOST_BACKEND=conf:phpfpm:tcp:php:9000
18+
ports:
19+
- "8000:80"
20+
- "8443:443"
21+
volumes:
22+
- ./www:/var/www/default/htdocs
23+
depends_on:
24+
- php
25+
26+
# PHP-FPM Server
27+
php:
28+
image: devilbox/php-fpm:8.2-base
29+
hostname: php
30+
environment:
31+
- NEW_UID=1000
32+
- NEW_GID=1000
33+
volumes:
34+
- ./www:/var/www/default/htdocs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
docker-compose build
8+
docker-compose up -d
9+
sleep 10
10+
11+
if ! curl http://localhost:8000 | grep '[OK]'; then
12+
docker-compose logs || true
13+
docker-compose stop || true
14+
docker-compose rm -f || true
15+
exit 1
16+
fi
17+
if ! curl -k https://localhost:8443 | grep '[OK]'; then
18+
docker-compose logs || true
19+
docker-compose stop || true
20+
docker-compose rm -f || true
21+
exit 1
22+
fi
23+
24+
docker-compose logs || true
25+
docker-compose stop || true
26+
docker-compose rm -f || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[OK]
2+
<h1>PHP version: <?php echo phpversion();?></h1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Example: Reverse Proxy (NodeJS)
2+
3+
Docker Compose example with HTTPD acting as a Reverse Proxy and a remote NodeJS server.
4+
5+
## Run
6+
```bash
7+
docker-compose up
8+
```
9+
10+
## View
11+
```bash
12+
# HTTP
13+
curl http://localhost:8000
14+
15+
# HTTPS
16+
curl -k https://localhost:8443
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
version: '2.3'
3+
4+
services:
5+
6+
# HTTPD Server
7+
httpd:
8+
image: devilbox/nginx-stable:alpine
9+
build:
10+
context: ../../Dockerfiles
11+
dockerfile: Dockerfile.alpine
12+
hostname: httpd
13+
environment:
14+
- MAIN_VHOST_BACKEND=conf:rproxy:http:node:3000
15+
- MAIN_VHOST_SSL_TYPE=both
16+
ports:
17+
- "8000:80"
18+
- "8443:443"
19+
depends_on:
20+
- node
21+
22+
# NodeJS Server
23+
node:
24+
image: node:19-alpine
25+
hostname: node
26+
command: node /app/app.js
27+
volumes:
28+
- ./www:/app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
docker-compose build
8+
docker-compose up -d
9+
sleep 10
10+
11+
if ! curl http://localhost:8000 | grep '[OK]'; then
12+
docker-compose logs || true
13+
docker-compose stop || true
14+
docker-compose rm -f || true
15+
exit 1
16+
fi
17+
if ! curl -k https://localhost:8443 | grep '[OK]'; then
18+
docker-compose logs || true
19+
docker-compose stop || true
20+
docker-compose rm -f || true
21+
exit 1
22+
fi
23+
24+
docker-compose logs || true
25+
docker-compose stop || true
26+
docker-compose rm -f || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const http = require('http');
2+
const server = http.createServer((req, res) => {
3+
res.statusCode = 200;
4+
res.setHeader('Content-Type', 'text/plain');
5+
res.write('[OK]\n');
6+
res.write('NodeJS is running\n');
7+
res.end();
8+
});
9+
server.listen(3000, '0.0.0.0');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Example: Reverse Proxy (Python)
2+
3+
Docker Compose example with HTTPD acting as a Reverse Proxy and a remote Python server.
4+
5+
## Run
6+
```bash
7+
docker-compose up
8+
```
9+
10+
## View
11+
```bash
12+
# HTTP
13+
curl http://localhost:8000
14+
15+
# HTTPS
16+
curl -k https://localhost:8443
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
version: '2.3'
3+
4+
services:
5+
6+
# HTTPD Server
7+
httpd:
8+
image: devilbox/nginx-stable:alpine
9+
build:
10+
context: ../../Dockerfiles
11+
dockerfile: Dockerfile.alpine
12+
hostname: httpd
13+
environment:
14+
- MAIN_VHOST_BACKEND=conf:rproxy:http:python:3000
15+
- MAIN_VHOST_SSL_TYPE=both
16+
ports:
17+
- "8000:80"
18+
- "8443:443"
19+
depends_on:
20+
- python
21+
22+
# Python Server
23+
python:
24+
image: python:3-alpine
25+
hostname: python
26+
command: sh -c "pip install aiohttp==3.8.3; python -u /app/server.py"
27+
volumes:
28+
- ./www:/app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
docker-compose build
8+
docker-compose up -d
9+
sleep 10
10+
11+
if ! curl http://localhost:8000 | grep '[OK]'; then
12+
docker-compose logs || true
13+
docker-compose stop || true
14+
docker-compose rm -f || true
15+
exit 1
16+
fi
17+
if ! curl -k https://localhost:8443 | grep '[OK]'; then
18+
docker-compose logs || true
19+
docker-compose stop || true
20+
docker-compose rm -f || true
21+
exit 1
22+
fi
23+
24+
docker-compose logs || true
25+
docker-compose stop || true
26+
docker-compose rm -f || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from aiohttp import web
2+
3+
async def handle(request):
4+
response = '[OK]\nHello from Python\n'
5+
return web.Response(text=response)
6+
7+
app = web.Application()
8+
app.router.add_get('/', handle)
9+
app.router.add_get('/{name}', handle)
10+
11+
web.run_app(app, port=3000)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Example: Static files
2+
3+
Docker Compose example with only serving static files.
4+
5+
## Run
6+
```bash
7+
docker-compose up
8+
```
9+
10+
## View
11+
```bash
12+
curl http://localhost:8000
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
version: '2.3'
3+
4+
services:
5+
6+
# HTTPD Server
7+
httpd:
8+
image: devilbox/nginx-stable:alpine
9+
build:
10+
context: ../../Dockerfiles
11+
dockerfile: Dockerfile.alpine
12+
hostname: httpd
13+
environment:
14+
- NEW_UID=1000
15+
- NEW_GID=1000
16+
ports:
17+
- "8000:80"
18+
volumes:
19+
- ./www:/var/www/default/htdocs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
docker-compose build
8+
docker-compose up -d
9+
sleep 10
10+
11+
if ! curl http://localhost:8000 | grep '[OK]'; then
12+
docker-compose logs || true
13+
docker-compose stop || true
14+
docker-compose rm -f || true
15+
exit 1
16+
fi
17+
18+
docker-compose logs || true
19+
docker-compose stop || true
20+
docker-compose rm -f || true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[OK]
2+
<h1>It works!</h1>

0 commit comments

Comments
 (0)