Nginx 在位置中重写为反向代理的代理\传递
我的NGINX反向代理上有一个.conf文件。 我收到一个请求URL,如: 我需要让它将/messaging转换成/system/console,转换成一个karaf容器。 这看起来很简单,但事实并非如此,我会更好地解释原因 容器位于不同的子域中,如 我能让它工作的唯一方法是不加载任何静态文件(图像、js、css),只加载html,如下所示:Nginx 在位置中重写为反向代理的代理\传递,nginx,Nginx,我的NGINX反向代理上有一个.conf文件。 我收到一个请求URL,如: 我需要让它将/messaging转换成/system/console,转换成一个karaf容器。 这看起来很简单,但事实并非如此,我会更好地解释原因 容器位于不同的子域中,如 我能让它工作的唯一方法是不加载任何静态文件(图像、js、css),只加载html,如下所示: location /messaging { expires -1; add_header 'Cache-Control' 'no-store, no-
location /messaging {
expires -1;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
rewrite /messaging/(.*) /$1 last;
proxy_pass http://subdomain.local.example.com/system/console/;
}
通过上述方式,可在以下位置请求图像:
而不是消息/system/console/res/flags/en.gif
这是我的完整配置文件(不幸的是,这里的缩进不正确,我可以保证它在配置文件上是正确的):
最后,我不想将/messaging重定向到/,因为我有一个默认的/address,它已经重定向到其他路径。
所以我不想添加/system-location,因为我会有更多的卡夫卡容器。
我想了解为什么在/messaging位置内无法识别所有请求,为什么有些请求被重定向到/system/console/
有人能帮我理解我做错了什么吗?
非常感谢你的帮助
致以最良好的祝愿,
Luis Nabais您可以将URI从
/messaging/foo
重写为/system/console/foo
,因为它以两种方式向上游传递
方法一使用location
和proxy\u-pass
指令进行翻译。例如:
location /messaging {
expires -1;
add_header ...;
proxy_pass http://subdomain.local.example.com/system/console;
}
location /messaging {
expires -1;
add_header ...;
rewrite /messaging(/.*)?$ /system/console$1 break;
proxy_pass http://subdomain.local.example.com;
}
位置
和代理传递
语句上的URI都应该有尾随/
,或者两者都没有尾随/
。有关详细信息,请参阅
方法二使用
重写…中断
。例如:
location /messaging {
expires -1;
add_header ...;
proxy_pass http://subdomain.local.example.com/system/console;
}
location /messaging {
expires -1;
add_header ...;
rewrite /messaging(/.*)?$ /system/console$1 break;
proxy_pass http://subdomain.local.example.com;
}
您必须使用
中断
,因为重写的URI需要在同一位置
块中处理。有关详细信息,请参阅。您可以将URI从/messaging/foo
重写为/system/console/foo
,因为它以两种方式向上游传递
方法一使用location
和proxy\u-pass
指令进行翻译。例如:
location /messaging {
expires -1;
add_header ...;
proxy_pass http://subdomain.local.example.com/system/console;
}
location /messaging {
expires -1;
add_header ...;
rewrite /messaging(/.*)?$ /system/console$1 break;
proxy_pass http://subdomain.local.example.com;
}
位置
和代理传递
语句上的URI都应该有尾随/
,或者两者都没有尾随/
。有关详细信息,请参阅
方法二使用
重写…中断
。例如:
location /messaging {
expires -1;
add_header ...;
proxy_pass http://subdomain.local.example.com/system/console;
}
location /messaging {
expires -1;
add_header ...;
rewrite /messaging(/.*)?$ /system/console$1 break;
proxy_pass http://subdomain.local.example.com;
}
您必须使用
中断
,因为重写的URI需要在同一位置
块中处理。有关详细信息,请参阅。您是否试图通过http://www.example.com/messaging/foo
至http://subdomain.local.example.com/system/console/foo
?你好,Richard。谢谢你的回答:)是的,想法就是这样!你想通过http://www.example.com/messaging/foo
至http://subdomain.local.example.com/system/console/foo
?你好,Richard。谢谢你的回答:)是的,想法就是这样!那正是我所想的。但在这两种情况下,不知何故URL被重写,/消息部分被忽略,因此静态文件无法正确打开,它们是这样打开的:而不是。不知何故,它被重定向到/,被位置/捕获。这正是我所想的。但是在这两种情况下,不知何故URL被重写,/消息部分被忽略,因此静态文件无法正确打开,它们是这样打开的:而不是。不知何故,它被重定向到/,由位置/捕获。