部署配置:新增裸机(非 Docker)部署所需的 systemd/Nginx 模板
- deploy/systemd/wagtailcms-backend.service:gunicorn 后端服务,unix socket 监听 - deploy/systemd/wagtailcms-frontend.service:Next.js 前端服务(npm run start) - deploy/nginx/wagtailcms.conf:反向代理模板,区分管理后台域名与前端站点域名 供阿里云 ECS 等裸机环境不使用 Docker 时直接部署参考。
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# 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` 指令。
|
||||
@@ -0,0 +1,30 @@
|
||||
[Unit]
|
||||
Description=wagtailcms Django/Wagtail backend (gunicorn)
|
||||
After=network.target postgresql.service redis-server.service
|
||||
Wants=postgresql.service redis-server.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=wagtailcms
|
||||
Group=www-data
|
||||
WorkingDirectory=/srv/wagtailcms
|
||||
EnvironmentFile=/srv/wagtailcms/.env
|
||||
RuntimeDirectory=wagtailcms
|
||||
RuntimeDirectoryMode=0755
|
||||
ExecStart=/srv/wagtailcms/.venv/bin/gunicorn wagtailcms.wsgi:application \
|
||||
--bind unix:/run/wagtailcms/gunicorn.sock \
|
||||
--workers 3 \
|
||||
--timeout 60 \
|
||||
--access-logfile - \
|
||||
--error-logfile -
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
# 加固(可按需调整)
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,22 @@
|
||||
[Unit]
|
||||
Description=wagtailcms Next.js frontend
|
||||
After=network.target wagtailcms-backend.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=wagtailcms
|
||||
Group=wagtailcms
|
||||
WorkingDirectory=/srv/wagtailcms/frontend
|
||||
EnvironmentFile=/srv/wagtailcms/frontend/.env.production
|
||||
Environment=PORT=3000
|
||||
Environment=NODE_ENV=production
|
||||
ExecStart=/usr/bin/npm run start
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user