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

Nginx Proxy Manager自定义路径重定向问题:Stirling PDF代理异常

Stirling PDF 反向代理子路径配置解决方案(Nginx Proxy Manager)

环境信息

  • 群晖NAS Docker环境
  • Nginx Proxy Manager(NPM):http://192.168.1.10:81(Docker部署)
  • Stirling PDF:http://192.168.1.10:5556

需求

  • 域名test.example.com根路径返回404,仅允许通过https://test.example.com/pdf访问Stirling PDF
  • 访问https://test.example.com/pdf需自动重定向到https://test.example.com/pdf/login,登录后跳转至https://test.example.com/pdf/的中文界面

核心问题

Stirling PDF默认基于根路径运行,反向代理子路径时,它的重定向、静态资源引用仍使用根路径,导致NPM无法正确映射,需同时调整Stirling PDF的上下文路径和NPM的代理规则。

解决方案步骤

1. 修改Stirling PDF的Docker启动参数

找到Stirling PDF的Docker容器,编辑启动配置,添加上下文路径环境变量:

JAVA_OPTS=-Dserver.servlet.context-path=/pdf

重启容器后,Stirling PDF的本地访问路径变为http://192.168.1.10:5556/pdf/,直接访问该地址应能正常显示登录页。

2. 配置Nginx Proxy Manager代理规则

进入NPM后台http://192.168.1.10:81,编辑test.example.com的代理主机:

  • 协议选择http
  • 转发主机名/IP填192.168.1.10,转发端口填5556
  • SSL保持现有Let's Encrypt配置,勾选全部选项
  • 高级配置替换为以下Nginx规则:
location / {
    return 404;
}

location /pdf {
    proxy_pass http://192.168.1.10:5556/pdf;
    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;
    proxy_set_header X-Forwarded-Port $server_port;
    # 修正重定向路径
    proxy_redirect http://$host:5556/pdf/ https://$host/pdf/;
    proxy_redirect http://$host:5556/pdf https://$host/pdf;
}

location /pdf/ {
    proxy_pass http://192.168.1.10:5556/pdf/;
    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;
    proxy_set_header X-Forwarded-Port $server_port;
}

保存并应用配置。

3. 设置Stirling PDF为中文界面

登录Stirling PDF后,点击右上角用户图标选择Settings,在Language选项中选择中文(简体),保存设置即可。

验证

  • 访问https://test.example.com返回404,符合根路径限制要求
  • 访问https://test.example.com/pdf自动跳转至https://test.example.com/pdf/login,登录后进入中文界面,静态资源加载正常

内容的提问来源于stack exchange,提问作者Shengu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 00:33:23