|
| 1 | +# HTTPS配置 |
| 2 | + |
| 3 | +## 使用程序内置HTTPS |
| 4 | + |
| 5 | +如果想通过HTTPS访问程序,可以通过编辑配置文件 `config/config.yaml` 和 `docker-compose.yaml` 实现 |
| 6 | + |
| 7 | +> [!WARNING] |
| 8 | +> 如果使用了HTTPS,服务器就无法使用 `Nginx`、`Caddy` 等反代工具,因为这些工具会占用443端口,和程序内置的https端口冲突 |
| 9 | +
|
| 10 | +::: code-group |
| 11 | + |
| 12 | +```yaml [config.yaml] |
| 13 | +server: |
| 14 | + adminPath: /admin |
| 15 | + address: :1024 # 项目http端口 |
| 16 | + httpsAddr: :443 # 项目https端口 // [!code focus] |
| 17 | + httpsCertPath: keys/ssl.pem # ssl证书公钥地址 // [!code focus] |
| 18 | + httpsKeyPath: keys/ssl.key # ssl证书私钥地址 // [!code focus] |
| 19 | + logPath: logs |
| 20 | + logStdout: false |
| 21 | + |
| 22 | +database: |
| 23 | + default: |
| 24 | + link: mysql:root:fakeoai@tcp(mysql:3306)/share?loc=Local&parseTime=true |
| 25 | + charset: utf8mb4 |
| 26 | + |
| 27 | +redis: |
| 28 | + default: |
| 29 | + address: redis:6379 |
| 30 | + pass: fakeoai |
| 31 | + db: 0 |
| 32 | +``` |
| 33 | +
|
| 34 | +```yaml [docker-compose.yaml] |
| 35 | + share: |
| 36 | + image: fakeoai/share |
| 37 | + # image: fakeoai/share-thirdparty # 第三方模式镜像 |
| 38 | + container_name: share |
| 39 | + restart: always |
| 40 | + environment: |
| 41 | + TZ: Asia/Shanghai |
| 42 | + ports: |
| 43 | + - 1024:1024 |
| 44 | + - 443:443 # 打开docker内的https端口 // [!code focus] |
| 45 | + volumes: |
| 46 | + - ./config:/app/config |
| 47 | + - ./keys:/app/keys |
| 48 | + - ./logs:/app/logs |
| 49 | + - ./public:/app/public |
| 50 | + depends_on: |
| 51 | + - redis |
| 52 | + - mysql |
| 53 | +``` |
| 54 | +
|
| 55 | +::: |
| 56 | +
|
| 57 | +## 使用Nginx反代 |
| 58 | +
|
| 59 | +如果不想使用程序内置的HTTPS,可以使用Nginx反代实现,如下是Nginx的配置示例 |
| 60 | +
|
| 61 | +```nginx |
| 62 | +server { |
| 63 | + listen 443 ssl; |
| 64 | + server_name site1.example.com; # 你的网站域名 |
| 65 | + ssl_certificate /path/to/cert.pem; # ssl证书公钥地址 |
| 66 | + ssl_certificate_key /path/to/key.pem; # ssl证书私钥地址 |
| 67 | + |
| 68 | + location / { |
| 69 | + proxy_pass http://localhost:1024; # share的地址 |
| 70 | + proxy_set_header Host $host; # 必须配置!!! |
| 71 | + proxy_set_header X-Forwarded-Proto $scheme; # 必须配置!!! |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +# 多站点配置 |
| 76 | +server { |
| 77 | + listen 443 ssl; |
| 78 | + server_name site2.example.com; # 你的网站域名 |
| 79 | + ssl_certificate /path/to/cert.pem; # ssl证书公钥地址 |
| 80 | + ssl_certificate_key /path/to/key.pem; # ssl证书私钥地址 |
| 81 | + |
| 82 | + location / { |
| 83 | + proxy_pass http://localhost:1024; # share的地址 |
| 84 | + proxy_set_header Host $host; # 必须配置!!! |
| 85 | + proxy_set_header X-Forwarded-Proto $scheme; # 必须配置!!! |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## 使用Caddy反代 |
| 91 | + |
| 92 | +如果不想使用程序内置的HTTPS,可以使用Caddy反代实现,如下是Caddy的配置示例 |
| 93 | + |
| 94 | +```nginx |
| 95 | +site1.example.com { |
| 96 | + tls /path/to/cert.pem /path/to/key.pem # ssl证书公钥和私钥地址 |
| 97 | + reverse_proxy http://localhost:1024 { |
| 98 | + header_up Host {host} # 必须配置!!! |
| 99 | + header_up X-Forwarded-Proto {scheme} # 必须配置!!! |
| 100 | + } |
| 101 | +} |
| 102 | +
|
| 103 | +# 多站点配置 |
| 104 | +site2.example.com { |
| 105 | + tls /path/to/cert.pem /path/to/key.pem # ssl证书公钥和私钥地址 |
| 106 | + reverse_proxy http://localhost:1024 { |
| 107 | + header_up Host {host} # 必须配置!!! |
| 108 | + header_up X-Forwarded-Proto {scheme} # 必须配置!!! |
| 109 | + } |
| 110 | +} |
| 111 | +``` |
0 commit comments