如何nginx重写和代理? http://sa.com/rabbitmq/api/#/queues/%2F/somequeue

时间:2015-08-24 10:21:15

标签: nginx proxy rabbitmq

我尝试使用单个域来代理几个这样的程序:

http://sa.com/rabbitmq/ ---> http://localhost:15672/ http://sa.com/zabbix/ ---> http://localhost:10000/

和我的混乱是打击:

location /rabbitmq { rewrite /rabbitmq(.*) $1 break; proxy_pass http://localhost:15672;

在点击队列名称观看细节之前,它很有效, 哪个网址如标题所示: http://sa.com/rabbitmq/api/#/queues/%2F/somequeue

发生404错误,我在chrome的开发工具中看到了一个请求:

http://rabbitmq.testing.gotokeep.com:15672/api/queues/%2F/dailyNewLike?lengths_age=60&lengths_incr=5&msg_rates_age=60&msg_rates_incr=5

此请求返回404。

我想当处理rewrite时,uri被解码(... /%2F / ... - > ... /// ...)并且将删除额外的斜杠。 ..

我猜对了吗?有解决方案吗?

2 个答案:

答案 0 :(得分:1)

您的猜测很好,但不是,真正的问题是nginx将%2F转换为%252F% - > %25)。

%2Fvhost名称(/)。我没有找到解决此问题的真正解决方案,我的解决方法是使用不包含vhost符号的其他/名称(例如pool1)。

答案 1 :(得分:0)

您可以使用$ request_uri防止nginx解码uri。 像下面一样使用conf

location /rabbitmq {
    if ($request_uri ~* "/rabbitmq/(.*)") {
        proxy_pass http://localhost:15672/$1;
    }
}