获取与Web服务器一起使用的传输Web界面

获取与Web服务器一起使用的传输Web界面

我在默认端口上工作,并且希望能够使用具有类似 的 URL 的 Web 界面http://my.domain/torrents

我尝试向 Nginx 添加位置和代理配置,但它无法完全工作。我猜这是因为网络界面重定向。

server {
    root /data/www;
    autoindex on;

    server_name localhost;

    location / {
            try_files $uri $uri/ /index.html;
    }

    location /torrents/ {
            proxy_pass_header  X-Transmission-Session-Id;
            proxy_pass         http://127.0.0.1:9091;
    }
}

这个conf失败,因为它无法到达/transmission/rpc404 /usr/share/transmission/web/rpc)我已经尝试了很多东西,但我总是缺少一些东西。 transmission/rpctransmission/uploadtransmission/webtransmission/javascript/whatever...

答案1

我现在可以通过配置中的以下位置使其正常工作:

      location /transmission {
              proxy_pass http://127.0.0.1:9091;
              proxy_pass_header X-Transmission-Session-Id;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }

当我访问 时/transmission/,我收到 409 错误,指出我的标头无效X-Transmission-Session-Id,但当我访问时,/transmission/web一切似乎都正常。

答案2

有一个工作样本Linux服务器.io存储库。

https://github.com/linuxserver/reverse-proxy-confs/blob/master/transmission.subfolder.conf.sample

如果您不使用 docker,配置可能如下所示。

location ^~ /transmission {
    include proxy.conf;
    proxy_pass http://127.0.0.1:9091;
    proxy_pass_header  X-Transmission-Session-Id;
}

location ^~ /transmission/rpc {
    include proxy.conf;
    proxy_pass http://127.0.0.1:9091;
}

proxy.conf是在https://github.com/linuxserver/docker-swag/blob/master/root/defaults/nginx/proxy.conf.sample

答案3

您的配置表明只有以 开头的网址才/torrents/应该被 proxy_passed 到http://127.0.0.1:9091。对于任何其他 url(例如/transmissionnginx)将使用第一个位置/,因此不会 proxy_pass 将其传递到后端。

如果您希望每个请求都代理传递到后端,则需要此位置而不是现有的两个位置:

location / {
        proxy_pass_header  X-Transmission-Session-Id;
        proxy_pass         http://127.0.0.1:9091;
}

答案4

请注意,这似乎仍然在第一个 RPC 调用上抛出一个 409,但这只是在日志中,否则似乎工作得很好

为了解决 /transmission 无法直接工作并需要转到 /transmission/web 的问题,我添加了重写规则。其余部分已由@replay 提供。

我有一个 SSL 重定向和一些其他服务在此 nginx 上运行,因此不能仅通过代理传递所有内容 /

假设 - 所有非“/”终止的路径都被重定向到 /,例如 mydomain.com/transmission 将被重定向到 mydomain.com/transmission/

# Redirect /transmission to /transmission/web/ to get around the CSRF token issues
                location = /transmission/ {
                        return 301 /transmission/web/;
                }
# Actually proxy with the session id header 
# We need a separate proxy for /transmission, which is the webpage and assets and a separate for the rpc calls which go to the server root
                location ^~ /transmission {
                        include proxy.conf;
                        proxy_pass http://127.0.0.1:9091/transmission;
                        proxy_pass_header X-Transmission-Session-Id;
                }
                location ^~ /transmission/rpc {
                        include proxy.conf;
                        proxy_pass http://127.0.0.1:9091;
                }


我相信代理配置详细信息只是默认值

# Version 2023/02/09 - Changelog: https://github.com/linuxserver/docker-swag/commits/master/root/defaults/nginx/proxy.conf.sample

# Timeout if the real server is dead
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

# Proxy Connection Settings
proxy_buffers 32 4k;
proxy_connect_timeout 240;
proxy_headers_hash_bucket_size 128;
proxy_headers_hash_max_size 1024;
proxy_http_version 1.1;
proxy_read_timeout 240;
proxy_redirect http:// $scheme://;
proxy_send_timeout 240;

# Proxy Cache and Cookie Settings
proxy_cache_bypass $cookie_session;
#proxy_cookie_path / "/; Secure"; # enable at your own risk, may break certain apps
proxy_no_cache $cookie_session;

# Proxy Header Settings
#proxy_set_header Connection $connection_upgrade;
proxy_set_header Early-Data $ssl_early_data;
proxy_set_header Host $host;
proxy_set_header Proxy "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Method $request_method;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Uri $request_uri;
proxy_set_header X-Original-Method $request_method;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
proxy_set_header X-Real-IP $remote_addr;

相关内容