如何代理对特定 URL 的调用以使用 NGINX 泛滥?

How to proxy calls to specific URL to deluge using NGINX?

我想使用 NGINX 作为代理来访问我家庭网络中的 Deluge(NGINX 是公开可用的)。

此配置有效:

location 8112;

location / {
    proxy_pass http://deluge_address:8112;
}

但是我想使用 http://nginx_address/deluge 形式的地址代理到内部 http://deluge_address:8112

我尝试了以下方法:

location /deluge/ {
    proxy_pass http://deluge_address:8112/;
}

(我尝试了尾随 / - none 的不同组合)。

但我得到的是 404 Not found

我对网络有一定了解,但不多。 有人知道我做错了什么吗?

我确实找到了解决方案,但同时在 Nginx 中也发现了一个错误

https://trac.nginx.org/nginx/ticket/1370#ticket

编辑-1

我记录的错误似乎是无效的,它甚至帮助我了解了更多的东西。所以我稍微编辑了配置。

您需要使用以下配置

location ~* /deluge/(.*) {
    sub_filter_once off;
    sub_filter_types text/css;
    sub_filter '"base": "/"' '"base": "/deluge/"';
    sub_filter '<head>' '<head>\n<base href="/deluge/">';
    sub_filter 'src="/' 'src="./';
    sub_filter 'href="/' 'href="./';
    sub_filter 'url("/' 'url("./';
    sub_filter 'url(\'/' 'url(\'./';

    set $deluge_host 192.168.33.100;
    set $deluge_port 32770;
    proxy_pass http://$deluge_host:$deluge_port/;
    proxy_cookie_domain $deluge_host $host;
    proxy_cookie_path / /deluge/;
    proxy_redirect  http://$deluge_host:$deluge_port/ /deluge/;
}

关键是使用以下

将基数 url 插入到页面中
sub_filter '<head>' '<head>\n<base href="/deluge/">';

然后在html中的srchref属性进行替换。还有 css 个条目中的 url('

幸运的是,deluge 有一个 JavaScript 配置,它具有基础 url。所以我们可以通过添加

来覆盖相同的内容
sub_filter '"base": "/"' '"base": "/deluge/"';