73 lines
2.7 KiB
Plaintext
73 lines
2.7 KiB
Plaintext
# wagtailcms Windows Server 生产环境 Nginx 反向代理配置模板
|
||
# (Windows 版 nginx 不支持 Unix Domain Socket 反向代理到 gunicorn,
|
||
# 后端改用监听 127.0.0.1:8080 的 waitress,因此这里全部走 TCP 端口。)
|
||
#
|
||
# 使用方法:
|
||
# 1. 下载 nginx for Windows(http://nginx.org/en/download.html),解压到 C:\nginx
|
||
# 2. 将本文件内容追加/替换到 C:\nginx\conf\nginx.conf 的 http{} 块内
|
||
# (或用 include 语法:在 http{} 块中加一行 include wagtailcms.conf;,
|
||
# 并把本文件放到 C:\nginx\conf\wagtailcms.conf)
|
||
# 3. 将下面的 example.com / cms.example.com 替换为真实域名
|
||
# 4. nginx.exe -t 测试配置,nginx.exe -s reload 重载
|
||
#
|
||
# 架构:浏览器 -> Nginx(TLS 终止) -> {Next.js:3000(页面渲染) | waitress:8080(/admin /api /static /media 等后端路径)}
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 后端管理域名(Wagtail 管理后台 / API),对应 WAGTAILADMIN_BASE_URL
|
||
# ---------------------------------------------------------------------------
|
||
server {
|
||
listen 80;
|
||
server_name cms.example.com;
|
||
|
||
client_max_body_size 20m;
|
||
|
||
location /static/ {
|
||
alias C:/wagtailcms/staticfiles/;
|
||
access_log off;
|
||
expires 30d;
|
||
}
|
||
|
||
location /media/ {
|
||
alias C:/wagtailcms/media/;
|
||
access_log off;
|
||
expires 7d;
|
||
}
|
||
|
||
location / {
|
||
proxy_pass http://127.0.0.1:8080;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
}
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 前端站点域名(Next.js 页面),公众访问入口
|
||
# ---------------------------------------------------------------------------
|
||
server {
|
||
listen 80;
|
||
server_name www.example.com example.com;
|
||
|
||
client_max_body_size 20m;
|
||
|
||
location /_next/static/ {
|
||
proxy_pass http://127.0.0.1:3000;
|
||
proxy_set_header Host $host;
|
||
expires 30d;
|
||
access_log off;
|
||
}
|
||
|
||
location / {
|
||
proxy_pass http://127.0.0.1:3000;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
}
|
||
|
||
# 提示:申请到证书后(win-acme / 阿里云 SSL 证书服务下载 Nginx 格式证书),
|
||
# 手动加 `listen 443 ssl;` + `ssl_certificate`/`ssl_certificate_key` 指令,
|
||
# 并在 80 端口 server 块中加 `return 301 https://$host$request_uri;` 强制跳转。
|