feat: init
This commit is contained in:
commit
e6ee02e2f3
5
.env
Executable file
5
.env
Executable file
@ -0,0 +1,5 @@
|
||||
COMPOSE_PROJECT_NAME=gateway
|
||||
TZ=Asia/Shanghai
|
||||
TERM=xterm-256color
|
||||
|
||||
DIR=.
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/ngx/etc/.*
|
||||
/ngx/log
|
26
docker-compose.yaml
Executable file
26
docker-compose.yaml
Executable file
@ -0,0 +1,26 @@
|
||||
version: '3'
|
||||
|
||||
networks:
|
||||
local:
|
||||
name: local
|
||||
external: true
|
||||
|
||||
services:
|
||||
ngx:
|
||||
container_name: ngx
|
||||
image: nginx:latest
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
networks:
|
||||
- local
|
||||
volumes:
|
||||
- ${DIR}/ngx/etc/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ${DIR}/ngx/etc/conf.d:/etc/nginx/conf.d # 外层有公共参数定义
|
||||
- ${DIR}/ngx/log:/var/log/nginx
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
environment:
|
||||
TZ:
|
||||
TERM:
|
||||
|
1
ngx/etc/conf.d/includ.conf
Executable file
1
ngx/etc/conf.d/includ.conf
Executable file
@ -0,0 +1 @@
|
||||
include ./conf.d/*/*.conf;
|
38
ngx/etc/conf.d/model/site.cnf
Executable file
38
ngx/etc/conf.d/model/site.cnf
Executable file
@ -0,0 +1,38 @@
|
||||
upstream {stream_name} {
|
||||
server localhost:{port} weight=1;
|
||||
}
|
||||
|
||||
# ===================配置===================
|
||||
# 带加密的 web
|
||||
server {
|
||||
listen 80;
|
||||
listen 443 ssl http2;
|
||||
|
||||
charset utf-8;
|
||||
|
||||
server_name {server_name};
|
||||
|
||||
# 日志
|
||||
access_log ./conf.d/{name}/access.log;
|
||||
error_log ./conf.d/{name}/error.log;
|
||||
|
||||
#
|
||||
location / {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://{stream_name};
|
||||
}
|
||||
|
||||
location = /favicon.ico {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
root conf/path/to/site;
|
||||
}
|
||||
|
||||
# 自动重定向 80 到 443 开启 SSL
|
||||
# if ( $scheme = http ){
|
||||
# return 301 https://$server_name$request_uri;
|
||||
# }
|
||||
}
|
19
ngx/etc/conf.d/model/web.cnf
Executable file
19
ngx/etc/conf.d/model/web.cnf
Executable file
@ -0,0 +1,19 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen 443 ssl http2;
|
||||
|
||||
# 自动重定向 80 到 443 开启 SSL
|
||||
# if ( $scheme = http ){
|
||||
# return 301 https://$server_name$request_uri;
|
||||
# }
|
||||
|
||||
access_log ./conf.d/{server}/access.log;
|
||||
error_log ./conf.d/{server}/error.log;
|
||||
charset utf-8;
|
||||
|
||||
server_name {server_name};
|
||||
|
||||
|
||||
# web 根目录
|
||||
root /path/to/web;
|
||||
}
|
47
ngx/etc/nginx.conf
Executable file
47
ngx/etc/nginx.conf
Executable file
@ -0,0 +1,47 @@
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
########## 以下为自定义配置 ##########
|
||||
|
||||
#自定义变量 $connection_upgrade
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default keep-alive; # 默认为 keep-alive 一般 http 请求
|
||||
'websocket' upgrade; # 如果为 websocket 则 upgrade 升级
|
||||
}
|
||||
|
||||
#gzip on;
|
||||
# 关闭 ip 地址访问
|
||||
server {
|
||||
listen 80 default_server;
|
||||
# listen 443 ssl http2;
|
||||
server_name _;
|
||||
|
||||
return 403;
|
||||
}
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
35
readme.md
Normal file
35
readme.md
Normal file
@ -0,0 +1,35 @@
|
||||
# 使用 docker Gateway
|
||||
|
||||
## docker 网络配置
|
||||
|
||||
> 一个 docker 网段的创建关联一组 veth 配置,多个需要互相访问的服务尽量在同一网段下使用 docker network 通信,可以解决大多数由网络造成的访问问题。
|
||||
|
||||
1. 创建本地网段
|
||||
|
||||
```shell
|
||||
docker network create --ipv6 --subnet=2001:db8:abcd::/64 --gateway=2001:db8:abcd::1 --attachable local
|
||||
```
|
||||
|
||||
2. 容器加入本地网段
|
||||
```yaml
|
||||
# docker-compose.yaml
|
||||
networks:
|
||||
local:
|
||||
name: local
|
||||
external: true
|
||||
|
||||
services:
|
||||
ngx:
|
||||
container_name: ngx
|
||||
image: nginx:latest
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
networks:
|
||||
- local
|
||||
|
||||
# cmd
|
||||
docker run --networks=local nginx:latest
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user