Skip to content

Commit 39d85cb

Browse files
committed
example tutorial
1 parent 41b38d1 commit 39d85cb

File tree

10 files changed

+668
-0
lines changed

10 files changed

+668
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ networks:
232232

233233
一樣注意 networks 的部分,這邊多了 `external`,代表說我要用外部的 networks,如果找不到會報錯。
234234

235+
### 範例
236+
237+
[example](example)
238+
235239
#### 執行方法
236240

237241
先執行

example/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 說明
2+
3+
測試 domain
4+
5+
```cmd
6+
❯ curl -H "Host: whoami.A.local" localhost
7+
I'm b5ffefea7f65
8+
❯ curl -H "Host: whoami.B.local" localhost
9+
I'm b5ffefea7f65
10+
❯ curl -H "Host: whoami.C.local" localhost
11+
I'm b5ffefea7f65
12+
```
13+
14+
測試 `foo.com` 中的 `/nginx_status`
15+
16+
```cmd
17+
❯ curl -H "Host: foo.com" localhost/nginx_status
18+
Active connections: 1
19+
server accepts handled requests
20+
10 10 10
21+
Reading: 0 Writing: 1 Waiting: 0
22+
```
23+
24+
測試 domain 中 block http_user_agent,
25+
26+
```cmd
27+
❯ curl -H "Host: whoami.A.local" -I -A 'mj12bot' localhost
28+
curl: (52) Empty reply from server
29+
30+
❯ curl -H "Host: whoami.B.local" -I -A 'mj12bot' localhost
31+
HTTP/1.1 410 Gone
32+
Server: nginx/1.21.6
33+
Date: Sun, 15 May 2022 03:22:28 GMT
34+
Content-Type: text/html
35+
Content-Length: 143
36+
Connection: keep-alive
37+
38+
❯ curl -H "Host: whoami.C.local" -I -A 'mj12bot' localhost
39+
HTTP/1.1 200 OK
40+
Server: nginx/1.21.6
41+
Date: Sun, 15 May 2022 03:25:04 GMT
42+
Content-Type: text/plain; charset=utf-8
43+
Content-Length: 17
44+
Connection: keep-alive
45+
```
46+
W

example/custom_nginx.tmpl

Lines changed: 485 additions & 0 deletions
Large diffs are not rendered by default.

example/docker-compose.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: '3.5'
2+
services:
3+
4+
nginx-proxy:
5+
image: jwilder/nginx-proxy:alpine
6+
restart: always
7+
container_name: nginx-proxy
8+
ports:
9+
- "80:80"
10+
- "443:443"
11+
volumes:
12+
- /var/run/docker.sock:/tmp/docker.sock:ro
13+
- html:/usr/share/nginx/html
14+
- dhparam:/etc/nginx/dhparam
15+
# - vhost:/etc/nginx/vhost.d
16+
- ./vhost.d:/etc/nginx/vhost.d
17+
- certs:/etc/nginx/certs:ro
18+
- ./nginx.conf:/etc/nginx/nginx.conf
19+
- ./my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro
20+
- ./custom_nginx.tmpl:/app/nginx.tmpl
21+
- ./nginx_log:/var/log/nginx
22+
23+
nginx-proxy-letsencrypt:
24+
image: jrcs/letsencrypt-nginx-proxy-companion
25+
restart: always
26+
depends_on:
27+
- "nginx-proxy"
28+
volumes:
29+
- certs:/etc/nginx/certs
30+
# - vhost:/etc/nginx/vhost.d
31+
- ./vhost.d:/etc/nginx/vhost.d
32+
- html:/usr/share/nginx/html
33+
- /var/run/docker.sock:/var/run/docker.sock:ro
34+
environment:
35+
- ACME_CA_URI=https://acme-staging-v02.api.letsencrypt.org/directory
36+
- NGINX_PROXY_CONTAINER=nginx-proxy
37+
# - DEFAULT_EMAIL=xxx@xxx.xxx
38+
39+
whoami:
40+
image: jwilder/whoami
41+
environment:
42+
- VIRTUAL_HOST=foo.com,whoami.A.local,whoami.B.local,whoami.C.local
43+
44+
45+
volumes:
46+
certs:
47+
html:
48+
# vhost:
49+
dhparam:
50+
51+

example/my_proxy.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
client_max_body_size 6000m;
2+
proxy_read_timeout 720s;
3+
proxy_connect_timeout 720s;
4+
proxy_send_timeout 720s;
5+
6+
7+
# Add Headers for odoo proxy mode
8+
proxy_set_header X-Forwarded-Host $host;
9+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
10+
proxy_set_header X-Forwarded-Proto $scheme;
11+
proxy_set_header X-Real-IP $remote_addr;
12+
13+
# Gzip Compression
14+
gzip on;
15+
gzip_min_length 1024;
16+
gzip_types text/less image/x-icon image/bmp image/svg+xml;
17+
gzip_proxied expired no-cache no-store private auth;
18+
gzip_vary on;
19+
20+
21+
proxy_headers_hash_max_size 51200;
22+
proxy_headers_hash_bucket_size 6400;

example/nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log warn;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 2048;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
#tcp_nopush on;
25+
26+
keepalive_timeout 65;
27+
28+
#gzip on;
29+
30+
include /etc/nginx/conf.d/*.conf;
31+
}
32+
daemon off;

example/vhost.d/default

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#location / {
3+
# root /usr/share/nginx/html;
4+
# index index.html index.htm index.php;
5+
#}
6+
7+
8+
location /nginx_status {
9+
10+
stub_status on;
11+
access_log off;
12+
# access_log /usr/local/nginx/logs/status.log;
13+
# auth_basic "NginxStatus";
14+
15+
#allow xx.xxx.xx.xx;
16+
#deny all;
17+
}

example/vhost.d/whoami.A.local

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if ($http_user_agent ~* (MJ12bot) ) {
2+
return 444;
3+
}
4+
5+
6+

example/vhost.d/whoami.B.local

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if ($http_user_agent ~* (MJ12bot) ) {
2+
return 410;
3+
}
4+
5+

example/vhost.d/whoami.C.local

Whitespace-only changes.

0 commit comments

Comments
 (0)