UPDATE: run rabbitmq in a docker container

Follow these instructions to configure RabbitMq management and expose it on the web.

Check this post for instructions on how to setup RabbitMq on Ubuntu 16.04.

Enable Plugin

In order to list all the plugins and whether they are enabled or not, run:

sudo rabbitmq-plugins list
ubuntu:~$ sudo rabbitmq-plugins list
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@ip-172-30-0-140
 |/
[ ] amqp_client 3.6.12
[ ] cowboy 1.0.4
[ ] cowlib 1.0.2
[ ] rabbitmq_amqp1_0 3.6.12
[ ] rabbitmq_auth_backend_ldap 3.6.12
[ ] rabbitmq_auth_mechanism_ssl 3.6.12
[ ] rabbitmq_consistent_hash_exchange 3.6.12
[ ] rabbitmq_event_exchange 3.6.12
[ ] rabbitmq_federation 3.6.12
[ ] rabbitmq_federation_management 3.6.12
[ ] rabbitmq_jms_topic_exchange 3.6.12
[ ] rabbitmq_management 3.6.12
[ ] rabbitmq_management_agent 3.6.12
[ ] rabbitmq_management_visualiser 3.6.12
[ ] rabbitmq_mqtt 3.6.12
[ ] rabbitmq_recent_history_exchange 3.6.12
[ ] rabbitmq_sharding 3.6.12
[ ] rabbitmq_shovel 3.6.12
[ ] rabbitmq_shovel_management 3.6.12
[ ] rabbitmq_stomp 3.6.12
[ ] rabbitmq_top 3.6.12
[ ] rabbitmq_tracing 3.6.12
[ ] rabbitmq_trust_store 3.6.12
[ ] rabbitmq_web_dispatch 3.6.12
[ ] rabbitmq_web_mqtt 3.6.12
[ ] rabbitmq_web_mqtt_examples 3.6.12
[ ] rabbitmq_web_stomp 3.6.12
[ ] rabbitmq_web_stomp_examples 3.6.12
[ ] sockjs 0.3.4

To enable the management plugin:

sudo rabbitmq-plugins enable rabbitmq_management
ubuntu:~$ sudo rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
 amqp_client
 cowlib
 cowboy
 rabbitmq_web_dispatch
 rabbitmq_management_agent
 rabbitmq_management

Applying plugin configuration to your_node_name... started 6 plugins.

Optionally, you can also enable the visualizer plugin:

sudo rabbitmq-plugins enable rabbitmq_management_visualiser
ubuntu:~$ sudo rabbitmq-plugins enable rabbitmq_management_visualiser
The following plugins have been enabled:
 rabbitmq_management_visualiser

Applying plugin configuration to your_node_name... started 1 plugin.

Add User

By default, RabbitMq will only include one user after installation. The user name is guest and the password is guest, as well. The guest user access is limited to the localhost. In order to access it from another host, you will need to create a new user:

sudo rabbitmqctl add_user {USERNAME} {PASSWORD}
ubuntu:~$ sudo rabbitmqctl add_user admin password
Creating user "admin"

In order to access the management web site, the “administrator” tag has to be assigned to the user:

sudo rabbitmqctl set_user_tags {USERNAME} administrator
ubuntu:~$ sudo rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator]

Install and Configure Reverse Proxy

The management web site by default runs on port 15672. We could change the port, but instead, we will add NGINX as a reverse proxy:

Let’s install it:

sudo apt-get install nginx

Now let’s add a configuration file:

cd /etc/nginx/sites-available
sudo vi rabbitmq

The configuration could be something like:

server {
   listen 80;

   location / {
       proxy_pass http://localhost:15672;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
   }
}

You can also add a server_name to restrict it to a host name:

server_name rabbitmq.b2-4ac.com

Now to make it available:

cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/rabbitmq rabbitmq
sudo nginx -s reload

Control Access

If you are running a VPS you will want to make sure to open the port 80 and close access to all the other ports. In AWS EC2, you will want to modify the security group associated with your instance.

If your service provider doesn’t provide a firewall, you should try UFW.

Categories: TL;DR

0 Comments

Leave a Reply

Avatar placeholder