- deploy/systemd/wagtailcms-backend.service:gunicorn 后端服务,unix socket 监听 - deploy/systemd/wagtailcms-frontend.service:Next.js 前端服务(npm run start) - deploy/nginx/wagtailcms.conf:反向代理模板,区分管理后台域名与前端站点域名 供阿里云 ECS 等裸机环境不使用 Docker 时直接部署参考。
69 lines
2.4 KiB
Plaintext
69 lines
2.4 KiB
Plaintext
# wagtailcms 生产环境 Nginx 反向代理配置模板
|
||
# 使用方法:
|
||
# 1. 拷贝到 /etc/nginx/sites-available/wagtailcms.conf(Debian/Ubuntu)
|
||
# 或 /etc/nginx/conf.d/wagtailcms.conf(CentOS/Alibaba Cloud Linux)
|
||
# 2. 将下面的 example.com / cms.example.com 替换为真实域名
|
||
# 3. Debian/Ubuntu 需要 ln -s ../sites-available/wagtailcms.conf /etc/nginx/sites-enabled/
|
||
# 4. nginx -t && systemctl reload nginx
|
||
#
|
||
# 架构:浏览器 -> Nginx(TLS 终止) -> {Next.js:3000(页面渲染) | gunicorn unix socket(/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 /srv/wagtailcms/staticfiles/;
|
||
access_log off;
|
||
expires 30d;
|
||
}
|
||
|
||
location /media/ {
|
||
alias /srv/wagtailcms/media/;
|
||
access_log off;
|
||
expires 7d;
|
||
}
|
||
|
||
location / {
|
||
proxy_pass http://unix:/run/wagtailcms/gunicorn.sock;
|
||
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;
|
||
}
|
||
}
|
||
|
||
# 提示:拿到证书后(certbot --nginx 或阿里云 SSL 证书服务),
|
||
# certbot 会自动把以上两个 server 块改造成 443 + HTTP->HTTPS 跳转;
|
||
# 也可以手动加 `listen 443 ssl;` + `ssl_certificate`/`ssl_certificate_key` 指令。
|