rabbitmq in a docker-compose and behind a nginx proxy

4,474 views
Skip to first unread message

Luca Trazzi

unread,
Jun 26, 2018, 5:57:04 PM6/26/18
to rabbitmq-users

Hello guys,

I know there are some resources trying to address this particular problem, like this one https://stackoverflow.com/questions/48881248/rabbitmq-nginx-config

but I really wasn't successfull on making my UI page of rabbitmq work :(

this is my docker image

FROM rabbitmq:3-management


ADD
./docker/images/rabbitmq.conf /etc/rabbitmq/


RUN chown rabbitmq
:rabbitmq /etc/rabbitmq/rabbitmq.conf


CMD
["rabbitmq-server"]

using this configuration:

loopback_users = none
management
.path_prefix = /rabbitmq
default_user
= admin
default_pass
= ****


which run in a big docker-compose using

  rabbitmq:
    image
: "mygroup/rabbitmq"
    volumes
:
     
- mygroup-rabbitmq:/var/lib/rabbitmq
    expose
:
     
- "5672"
     
- "15672"

which runs under a SIMPLE nginx conf

location /rabbitmq {
                proxy_pass http
://rabbitmq;
                rewrite
^/rabbitmq/(.*)$ /$1 break;
                proxy_buffering                    off
;
                proxy_set_header
Host              $http_host;
                proxy_set_header X
-Real-IP         $remote_addr;
                proxy_set_header X
-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header X
-Forwarded-Proto $scheme;
           
}

where /rabbitmq is

upstream rabbitmq {
            least_conn
;
            server rabbitmq
:15672 weight=10 max_fails=3 fail_timeout=30s;
       
}

PROBLEM:

when I call my site with the following url https://website.me/rabbitmq I get the GUI page of the rabbitmq, but the relative paths of the javascript of the html page are trying to go to the root:


and as in the root I have my real webapp, this of course return 404.

What I'm doing wrong?

Thanks,
Luca


Luke Bakken

unread,
Jun 26, 2018, 7:02:29 PM6/26/18
to rabbitmq-users
Hi Luca,

Is there any difference if you browse to https://website.me/rabbitmq/ (note the trailing slash)?

Have you tried without https?

Have you tried outside of docker?

Can you capture a network transcript from Chrome dev tools? Please save to a file and attach to your response.

Thanks,
Luke

Luca Trazzi

unread,
Jun 27, 2018, 2:13:08 AM6/27/18
to rabbitmq-users
Hi :)

you can check yourself.


1) using trailing slash, it goes on infinite redirects, this can be easily explainable by the fact that upstream url is the same as as the path-prefix or rabbitmq

2) no I didn't, but I don't think it would change anything..

3) nah, I don't even remember how to install things outside docker :)

What I'm thinking, is that, shouldn't rabbit-mq webpage add that path-prefix configuration on the relative paths of the html page?

I mean these:

    <title>RabbitMQ Management</title>
   
<script src="js/ejs-1.0.min.js" type="text/javascript"></script>
   
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
   
<script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"></script>
   
<script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"></script>
   
<script src="js/sammy-0.7.6.min.js" type="text/javascript"></script>
   
<script src="js/json2-2016.10.28.js" type="text/javascript"></script>
   
<script src="js/base64.js" type="text/javascript"></script>
   
<script src="js/global.js" type="text/javascript"></script>
   
<script src="js/main.js" type="text/javascript"></script>
   
<script src="js/prefs.js" type="text/javascript"></script>
   
<script src="js/formatters.js" type="text/javascript"></script>
   
<script src="js/charts.js" type="text/javascript"></script>

shouldn't have the path prefix and then be something like

<script src="/rabbitmq/js/ejs-1.0.min.js" type="text/javascript"></script>

Or I'm guessing it wrong? Is path-prefix for another purpose?

Luca

Luke Bakken

unread,
Jun 27, 2018, 9:41:09 AM6/27/18
to rabbitmq-users
Hi Luca,

Thanks for all that info. I should have realized sooner that path_prefix isn't meant to be used in conjunction with a proxy that basically is doing the same thing.

In your case I'm pretty sure you can remove the path_prefix setting and it should work. Please give it a try and report back.

Thanks,
Luke

Luca Trazzi

unread,
Jun 27, 2018, 1:24:34 PM6/27/18
to rabbitmq-users
Ehi Luke,

I removed the path_prefix, now the https://scarab.me/rabbitmq gives me 404 with this message, {"error":"Object Not Found","reason":"Not Found"}, which is coming from rabbitmq, not the nginx.

Luke Bakken

unread,
Jun 27, 2018, 2:37:59 PM6/27/18
to rabbitmq-users
Hi Luca,

I can see if I can reproduce this locally. I don't use docker at all, so that will be one difference between my env and yours.

Luke Bakken

unread,
Jun 27, 2018, 7:41:59 PM6/27/18
to rabbitmq-users
Hi Luca,

I have attached the RabbitMQ and nginx configuration that I tested with (RabbitMQ 3.7.6).

Without the rewrite redirect rule in the config, if I visited this URL, I got the 404 message you see:


However, if I added the trailing slash, it worked fine:


Here's the reason why - when your browser's "base URL" does not end in a slash, it does not prepend that base to relative links within the HTML document it renders, which is why the javascript files weren't retrieved correctly. When you end the URL with a slash, your browser will take the following HTML -


<script src="js/ejs-1.0.min.js" type="text/javascript"></script>

... and will make the following request:

GET http://localhost:8888/rabbitmq/js/ejs-1.0.min.js

So, this really is an issue with your browser behavior when a URL does not include the trailing slash. To work around that, configure nginx to send a permanent redirect for the "slashless" URL.

One final tip - when testing permanent redirects in Chrome, be sure to test in an incognito window or those 301 redirects are permanently remembered by Chrome and the only way to clear them is to clear your browsing history at least over the past hour.

Thanks,
Luke

On Wednesday, June 27, 2018 at 10:24:34 AM UTC-7, Luca Trazzi wrote:
rabbitmq.conf
nginx.conf

Luca Trazzi

unread,
Jun 28, 2018, 5:40:53 AM6/28/18
to rabbitmq-users
You are the man, can I owe you a beer somewhere? With a donation? I'm speaking seriously.

Luke Bakken

unread,
Jun 28, 2018, 12:03:40 PM6/28/18
to rabbitmq-users
Hi Luca,

After further testing, that wasn't quite right as api calls failed due to nginx rewriting the request URI.

Please try this configuration out -


Thanks -
Luke

Luca Trazzi

unread,
Jun 28, 2018, 12:55:09 PM6/28/18
to rabbitmq-users
This updated conf works even better, now I can go on details of the queues ;) Thanks you again for your help.

Zakrava Corp.

unread,
Sep 18, 2022, 4:10:12 PM9/18/22
to rabbitmq-users
Hi Luke,

please, can you make that gist configuration available again?
I have the same issue as Luca and your gist link isn't working.
I am not using dockerized rabbitmq tho, that doesn't matter.

Thank you
Reply all
Reply to author
Forward
0 new messages