某些应用程序(例如Sonarr)是在假设它们可能被反向代理到子文件夹的情况下进行编程的。应用程序设置中有一个有用的选项-通常称为“ URL Base”-会将您的子文件夹作为其所有链接/标题的前缀添加。如果您代理的应用具有这样的功能,那就啦!设置并忘记它。如果没有,则不能选择该解决方案。



Caddy 2模块已经完成,并且正在发布中,可以在响应正文中执行替换:https : //



Fixing the problem
Ultimately, to fix this issue, all links and redirects must match up to valid URLs that Caddy knows how to handle. Something’s gotta give; either the HTTP application must correct its URLs to add the subfolder you want, or you need to configure Caddy to let the app have the web root it wants.

  1. Upstream

Some apps, like Sonarr, are programmed with the assumption that they might be reverse proxied into a subfolder. There is a helpful option in the application’s settings - commonly referred to as a “URL Base” - which will add your subfolder as a prefix to all of its links/headers. If the app you’re proxying has a feature like this, hurrah! Set it and forget it. If not, this solution isn’t an option.

  1. In Caddy

A. By giving up the web root
You can use a subdomain instead, e.g., and proxy the entire web root. This configuration precludes the issue described above and will work for absolutely any HTTP application.

B. By HTML filtering/header rewriting (advanced)
Alternately, you could try to use Caddy as a filtering layer and intercept those incorrect links as they come downstream from your HTTP application.

A Caddy 2 module has been completed and is in the process of being published that can perform replacements in response bodies:

Using that plugin involves defining rules that Caddy uses to alter the HTML document it receives from the upstream HTTP application before sending it to the client. In this way, the client would receive the correct links in HTML.

Rewriting headers from upstream can be achieved already using Caddy’s reverse_proxy directive which changes headers only to or from the backend (or, to change any/all headers, you can use the header directive. In this way, you can fix Location redirects as well. Combined, if carefully executed, these two strategies can produce a neatly contained HTTP application inside a subfolder without requiring the app to explicitly support this behaviour.

最后修改:2020 年 11 月 30 日 10 : 51 PM