Loading

使用Caddy反向代理jellyfin与qbittorrnet

需求

家里服务器上跑了很多容器服务,每个容器都做端口映射比较麻烦。
希望通过反向代理将所有服务聚合到同一个端口实现类似网址导航的效果。

实现

相比nginx我使用配置更简单的Caddy进行反向代理,主要难点是编写正确的Caddyfile文件。

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

:80 {
        # Set this path to your site's directory.
        root * /usr/share/caddy

        # Enable the static file server.
        file_server

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000

        handle_path /jellyfin/* {
                reverse_proxy 127.0.0.1:8096
        }
        handle_path /qb/* {
                reverse_proxy 127.0.0.1:8080 {
                        header_up Host 127.0.0.1:8080
                        header_up -Origin
                        header_up -Referer
                }
        }
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

注意,仅仅这样jellyfin依然无法正常工作,还需要配合一个正确的到航页。
我选择修改默认的/usr/share/caddy/index.html实现。

<!DOCTYPE NETSCAPE-Bookmark-file-1>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    <TITLE>Caddy</TITLE>
    <H1>Bookmarks</H1>
    <DL><p>
        <DT><H3>Powered by Caddy</H3>
        <DL><p>
        <DT><A HREF="/jellyfin/web/index.html">jellyfin</A>
        <DT><A HREF="/qb/">qbittorrent</A>
        </DL><p>
        </DL><p>


个人倾向于使用host网络部署caddy方便内网访问

docker run -d --network host --name caddy caddy

之后只需要使用将Caddy容器的80端口映射到外网即可实现各种容器服务的集成访问。

参考

Caddy | Jellyfin
Qbittorrent WEBUI and caddy v2 - Help - Caddy Community

posted @ 2023-10-07 20:45  azureology  阅读(1135)  评论(0)    收藏  举报