You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Nginx将DigitalOcean上的Ghost博客代理到外部站点/blog子路径

实现https://kasacja-aut.pl/blog 代理到DigitalOcean上的Ghost博客

1. Cloudflare DNS配置

  • 确认主域名kasacja-aut.pl的DNS记录已指向dhosting.pl的服务器(外部站点正常运行的话这条应该已经配置好了)
  • 添加一条CNAME记录:主机名填blog,目标填DigitalOcean上Ghost服务器的公网IP或自定义域名,Cloudflare代理状态设为橙色云朵(开启代理),确保HTTPS流量由Cloudflare处理

2. 调整DigitalOcean上的Nginx配置

修改Ghost对应的Nginx配置文件(一般在/etc/nginx/sites-available/目录下),适配/blog子路径的反向代理:

server {
    listen 80;
    listen [::]:80;
    server_name kasacja-aut.pl;

    # 强制跳转HTTPS
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name kasacja-aut.pl;

    # 配置SSL证书,可用Cloudflare提供的证书或Let's Encrypt证书
    ssl_certificate /path/to/your/ssl/cert.pem;
    ssl_certificate_key /path/to/your/ssl/key.pem;

    location /blog {
        # 移除请求路径中的/blog前缀,让Ghost能正确处理路由
        rewrite ^/blog(.*)$ $1 break;
        # 转发到Ghost默认运行端口2368
        proxy_pass http://localhost:2368;
        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;
    }
}
  • 同步修改Ghost的config.production.json配置文件,把url字段设为https://kasacja-aut.pl/blog,确保Ghost生成的内部链接都是正确的子路径

3. dhosting.pl外部站点配置

因为dhosting.pl不支持Node.js,只需在外部站点的服务器配置里,把/blog路径的请求转发到Cloudflare(最终指向DigitalOcean的Ghost):

若外部站点用Nginx

在主站点的Nginx配置中添加:

location /blog {
    proxy_pass https://kasacja-aut.pl/blog;
    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;
}

若外部站点用Apache

先启用mod_proxy和mod_proxy_http模块,再添加:

ProxyPass /blog https://kasacja-aut.pl/blog
ProxyPassReverse /blog https://kasacja-aut.pl/blog

4. 验证与重启

  • 重启DigitalOcean上的Nginx:sudo systemctl restart nginx
  • 重启Ghost服务:sudo systemctl restart ghost_your-site-name(替换成你的Ghost服务名称)
  • 登录Cloudflare控制面板,清除全部缓存
  • 访问https://kasacja-aut.pl/blog测试是否正常加载

内容的提问来源于stack exchange,提问作者Ryan Slight Edge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 12:05:18