|
3 | 3 | import { Callout } from 'nextra/components';
|
4 | 4 |
|
5 | 5 | <Callout type="warning" emoji="⚠️">
|
6 |
| -此部分内容是可选的,在正常情况,你不需要参考这部分内容。以下部分仅针对有特定需求的用户进行参考。 |
| 6 | +此部分内容将说明一些额外的操作流程,根据自己需要进行配置。 |
| 7 | +</Callout> |
| 8 | + |
| 9 | +## 反向代理 |
| 10 | + |
| 11 | +在这里提供双域名(前端和后端各用一个域名)与单域名(前后端共用一个域名)的配置步骤。 |
| 12 | + |
| 13 | +当然不管使用哪种方法,都建议用控制面板(如宝塔、1Panel 等)的使用面板提供的反代功能单独粘贴对应的反代配置部分完成配置(需要删掉开头和结尾的 server 块),手写反代配置的大佬随意。 |
| 14 | + |
| 15 | +### 双域名 |
| 16 | + |
| 17 | +这里假定前端域名为 `www.example.com`,后端为 `server.example.com`。 |
| 18 | + |
| 19 | +以下是后端 `server.example.com` 反代配置部分 |
| 20 | + |
| 21 | +```nginx |
| 22 | +server { |
| 23 | + ## 反向代理开始 |
| 24 | + ## WebSocket |
| 25 | + location /socket.io { |
| 26 | + proxy_pass http://127.0.0.1:2333/socket.io; |
| 27 | + proxy_set_header Host $host; |
| 28 | + proxy_set_header X-Real-IP $remote_addr; |
| 29 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 30 | + proxy_set_header REMOTE-HOST $remote_addr; |
| 31 | + proxy_set_header Upgrade $http_upgrade; |
| 32 | + proxy_set_header Connection "upgrade"; |
| 33 | + proxy_buffering off; |
| 34 | + proxy_http_version 1.1; |
| 35 | + add_header Cache-Control no-cache; |
| 36 | + } |
| 37 | + ## Others |
| 38 | + location / { |
| 39 | + proxy_pass http://127.0.0.1:2333; |
| 40 | + proxy_set_header Host $host; |
| 41 | + proxy_set_header X-Real-IP $remote_addr; |
| 42 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 43 | + proxy_set_header REMOTE-HOST $remote_addr; |
| 44 | + add_header X-Cache $upstream_cache_status; |
| 45 | + } |
| 46 | + ## 反向代理结束 |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +前端 `www.example.com` 反代部分 |
| 51 | + |
| 52 | +```nginx |
| 53 | +server{ |
| 54 | + location ~* \.(gif|png|jpg|css|js|woff|woff2)$ { |
| 55 | + proxy_pass http://127.0.0.1:2323; |
| 56 | + proxy_set_header Host $host; |
| 57 | + proxy_set_header X-Real-IP $remote_addr; |
| 58 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 59 | + proxy_set_header REMOTE-HOST $remote_addr; |
| 60 | + expires 30d; |
| 61 | + } |
| 62 | + location ~* \/(feed|sitemap|atom.xml) { |
| 63 | + proxy_pass http://127.0.0.1:2333/$1; |
| 64 | + proxy_set_header Host $host; |
| 65 | + proxy_set_header X-Real-IP $remote_addr; |
| 66 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 67 | + proxy_set_header REMOTE-HOST $remote_addr; |
| 68 | + add_header X-Cache $upstream_cache_status; |
| 69 | + add_header Cache-Control max-age=60; |
| 70 | + } |
| 71 | + location / { |
| 72 | + proxy_pass http://127.0.0.1:2323; |
| 73 | + proxy_set_header Host $host; |
| 74 | + proxy_set_header X-Real-IP $remote_addr; |
| 75 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 76 | + proxy_set_header REMOTE-HOST $remote_addr; |
| 77 | + add_header X-Cache $upstream_cache_status; |
| 78 | + add_header Cache-Control no-cache; |
| 79 | + proxy_intercept_errors on; |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +<Callout type="info"> |
| 85 | +如果您使用此部分示例配置 Nginx 反向代理,您的: |
| 86 | +- API 地址为 `https://server.example.com/api/v2` |
| 87 | +- 前端(Kami/Shiro)地址为 `https://www.example.com` |
| 88 | +- GateWay 为 `https://server.example.com` |
| 89 | +- 后台为 `https://server.example.com/qaqdmin` |
| 90 | +- 本地后台为 `https://server.example.com/proxy/qaqdmin` |
| 91 | +</Callout> |
| 92 | + |
| 93 | +### 单域名 |
| 94 | + |
| 95 | +以下配置文件以 Nginx 为例,请自行修改 SSL 证书路径以及自己的网站域名。 |
| 96 | + |
| 97 | +若使用 Caddy 进行配置可参考 [Caddyfile 文件示例](https://github.com/mx-space/docker/blob/master/Caddyfile.example)进行相应修改。 |
| 98 | + |
| 99 | +```nginx |
| 100 | +server { |
| 101 | + ## 反向代理开始 |
| 102 | + ## WebSocket 地址 |
| 103 | + location /socket.io { |
| 104 | + proxy_set_header Upgrade $http_upgrade; |
| 105 | + proxy_set_header Connection "Upgrade"; |
| 106 | + proxy_buffering off; |
| 107 | + proxy_set_header Host $host; |
| 108 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 109 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 110 | + proxy_pass http://127.0.0.1:2333/socket.io; |
| 111 | + } |
| 112 | + ## API 地址 |
| 113 | + location /api/v2 { |
| 114 | + proxy_pass http://127.0.0.1:2333/api/v2; |
| 115 | + } |
| 116 | + ## 简读 render 地址 |
| 117 | + location /render { |
| 118 | + proxy_pass http://127.0.0.1:2333/render; |
| 119 | + } |
| 120 | + ## Kami 地址 |
| 121 | + location / { |
| 122 | + proxy_pass http://127.0.0.1:2323; |
| 123 | + } |
| 124 | + ## 后台地址 |
| 125 | + location /qaqdmin { |
| 126 | + proxy_pass http://127.0.0.1:2333/qaqdmin; |
| 127 | + } |
| 128 | + ## 本地后台地址 |
| 129 | + location /proxy { |
| 130 | + proxy_pass http://127.0.0.1:2333/proxy; |
| 131 | + } |
| 132 | + ## RSS 地址 |
| 133 | + location ~* \/(feed|sitemap|atom.xml) { |
| 134 | + proxy_pass http://127.0.0.1:2333/$1; |
| 135 | + } |
| 136 | + ## 反向代理结束 |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +完整示例如下 |
| 141 | + |
| 142 | +```nginx |
| 143 | +server { |
| 144 | + listen 80; |
| 145 | + listen 443 ssl http2 ; |
| 146 | + ## 绑定域名 |
| 147 | + server_name www.example.com; |
| 148 | + index index.html; |
| 149 | + proxy_set_header Host $host; |
| 150 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 151 | + proxy_set_header X-Forwarded-Host $server_name; |
| 152 | + proxy_set_header Upgrade $http_upgrade; |
| 153 | + proxy_set_header Connection "upgrade"; |
| 154 | + error_log /www/sites/www.example.com/log/error.log; |
| 155 | + access_log /www/sites/www.example.com/log/access.log; |
| 156 | + location /socket.io { |
| 157 | + proxy_set_header Upgrade $http_upgrade; |
| 158 | + proxy_set_header Connection "Upgrade"; |
| 159 | + proxy_set_header Host $host; |
| 160 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 161 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 162 | + proxy_pass http://127.0.0.1:2333/socket.io; |
| 163 | + } |
| 164 | + location /api/v2 { |
| 165 | + proxy_pass http://127.0.0.1:2333/api/v2; |
| 166 | + } |
| 167 | + location /render { |
| 168 | + proxy_pass http://127.0.0.1:2333/render; |
| 169 | + } |
| 170 | + location / { |
| 171 | + proxy_pass http://127.0.0.1:2323; |
| 172 | + } |
| 173 | + location /qaqdmin { |
| 174 | + proxy_pass http://127.0.0.1:2333/qaqdmin; |
| 175 | + } |
| 176 | + location /proxy { |
| 177 | + proxy_pass http://127.0.0.1:2333/proxy; |
| 178 | + } |
| 179 | + location ~* \/(feed|sitemap|atom.xml) { |
| 180 | + proxy_pass http://127.0.0.1:2333/$1; |
| 181 | + } |
| 182 | + ssl_certificate /www/sites/www.example.com/ssl/fullchain.pem; |
| 183 | + ssl_certificate_key /www/sites/www.example.com/ssl/privkey.pem; |
| 184 | + ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; |
| 185 | + ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK'; |
| 186 | + ssl_prefer_server_ciphers on; |
| 187 | + ssl_session_cache shared:SSL:10m; |
| 188 | + ssl_session_timeout 10m; |
| 189 | + error_page 497 https://$host$request_uri; |
| 190 | + limit_conn perserver 300; |
| 191 | + limit_conn perip 25; |
| 192 | + limit_rate 512k; |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +<Callout type="info"> |
| 197 | +如果您使用此部分示例配置 Nginx 反向代理,您的: |
| 198 | +- API 地址为 `https://www.example.com/api/v2` |
| 199 | +- 前端(Kami/Shiro)地址为 `https://www.example.com` |
| 200 | +- GateWay 为 `https://www.example.com` |
| 201 | +- 后台为 `https://www.example.com/qaqdmin` |
| 202 | +- 本地后台为 `https://www.example.com/proxy/qaqdmin` |
7 | 203 | </Callout>
|
8 | 204 |
|
9 | 205 | ## 配置其他 Redis 服务
|
|
0 commit comments