如何使用NGINX将对特定URL的调用代理到泛滥? [英] How to proxy calls to specific URL to deluge using NGINX?
问题描述
我想使用NGINX作为代理来访问位于我的家庭网络内部的Deluge(NGINX公开可用).
I want to use NGINX to as a proxy to get to Deluge which is inside my home network (NGINX is publically available).
此配置有效:
location 8112;
location / {
proxy_pass http://deluge_address:8112;
}
但是我想使用http://nginx_address/deluge
形式的地址代理到内部http://deluge_address:8112
.
However I'd like to use an address in form of http://nginx_address/deluge
to be proxied to internal http://deluge_address:8112
.
我尝试了以下操作:
location /deluge/ {
proxy_pass http://deluge_address:8112/;
}
(我尝试了尾随/
的不同组合-无效).
(I tried different combinations of trailing /
- none work).
但是我却得到了404 Not found
.
我对网络有一些了解,但是了解的不多. 有人知道我在做什么错吗?
I have some knowledge about networks, but not too much. Does anybody have any idea what I'm doing wrongly?
推荐答案
我确实找到了解决方案,但同时也在Nginx中发现了一个错误
I did find a solution for this, but found a bug also in Nginx in the same time
https://trac.nginx.org/nginx/ticket/1370#ticket
编辑1
好像我记录的错误是一个无效的错误,甚至还帮助我了解了几件事.因此,我对配置进行了一些编辑.
Seems like bug i logged was an invalid one, which even helped me understand few more things. So I edited the config a bit.
您需要使用以下配置
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/$1;
proxy_cookie_domain $deluge_host $host;
proxy_cookie_path / /deluge/;
proxy_redirect http://$deluge_host:$deluge_port/ /deluge/;
}
关键是使用下面的代码在页面中插入基本网址
The key was to insert a base url into the pages using below
sub_filter '<head>' '<head>\n<base href="/deluge/">';
,然后在html的src
和href
属性中进行替换.以及css条目中的url('
.
And then make replacement in src
and href
attributes in html. And also url('
in css entries.
幸运的是,洪水有一个包含基本URL的JavaScript配置.因此,我们可以通过添加
Luckily deluge has a JavaScript config which has the base url. So we can override the same by adding
sub_filter '"base": "/"' '"base": "/deluge/"';
这篇关于如何使用NGINX将对特定URL的调用代理到泛滥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!