Skip to content

Setting Up RabbitMQ on a Linux Server – Message Broker for Queues and Background Tasks

RabbitMQ on a Linux server: install it as a One-Click App or with Docker Compose, secure the AMQP port, create a dedicated vHost, and set up your first queue with Python.

30 November 202614 min read3 Views0 helpful

Introduction

RabbitMQ is an open-source message broker. Applications send it messages, RabbitMQ puts them in queues and passes them on to the programs that process them. The sender and recipient do not need to run at the same time or know about each other. This lets you distribute tasks across multiple workers, decouple services, and avoid losing jobs if a recipient is temporarily unavailable. RabbitMQ uses the AMQP protocol and comes with a browser-based management interface. In this guide, we show you two ways to get started: the easy way, as a One-Click App, which makes RabbitMQ and its management interface available over HTTPS, and a manual installation with Docker Compose. After that, you’ll create a dedicated virtual host and user, then send your first messages through a queue with Python.

When RabbitMQ Makes Sense on a VPS

RabbitMQ is useful as soon as multiple programs need to reliably exchange tasks or events. RabbitMQ is a good fit for a VPS if:

  • your application needs to offload slow tasks, such as sending emails, converting images, or generating reports. The web app puts the job in a queue, and a worker processes it in the background.
  • multiple services need to exchange events, such as a store notifying inventory, billing, and shipping after an order, without calling each service directly.
  • your software explicitly requires RabbitMQ, for example as a backend for Celery in Python projects or as a queue for workflows in n8n.
  • you want to handle traffic spikes: messages wait in the queue until a worker is available instead of being lost.
  • you need a central broker for development and testing that all your projects and team members can access.

RabbitMQ is less suitable if you only want to run a script in the background occasionally. A cron job is enough for that. For smart home devices using MQTT, a dedicated MQTT broker is simpler, and if you need to store and replay data streams over several months, Apache Kafka is a better choice.

The Easy Way: RabbitMQ as a One-Click App

The fastest way to get RabbitMQ is through the One-Click Apps on your VPS. The management interface is directly accessible over HTTPS using a domain, and the admin account’s username and password are generated automatically. You don’t need a reverse proxy or certificate.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Setting up One-Click Apps for instructions.
  • At least 1 GB of free RAM. RabbitMQ uses around 120 MB of RAM just after startup; usage increases with more messages, queues, and connections.
  • Port 5672 must not already be in use on the VPS, for example by a second RabbitMQ installation.

Install

  1. Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
  2. Search the app catalog for RabbitMQ and click Install on its card.
  3. Use a custom subdomain or zap.cloud is already selected, with a random name. Leave the option enabled or enter your own name, such as rabbitmq. You’ll use this domain to access the management interface over HTTPS.
  4. You don’t need to fill anything in under App configuration. PORT determines which VPS port RabbitMQ uses to accept AMQP connections. The default is 5672; leave it as is if the port is available.
  5. Click Queue installation.

Installation takes one to two minutes. After that, the app’s status is Online, and the app card shows the address SERVER_IP:5672 under Connection. Your programs use this address to reach RabbitMQ.

First Login to the Management Interface

RabbitMQ is installed with an admin account whose username and password are generated automatically. The default guest account is not available in the One-Click App.

  1. Click the gear icon on the app card and switch to App environment.
  2. Under Automatically generated values, you’ll find SERVICE_USER_RABBITMQ (username) and SERVICE_PASSWORD_RABBITMQ (password). Click the eye icon to show a value, or the icon next to it to copy it.
  3. Open the app using the Access link. You’ll see the RabbitMQ Management login page.
  4. Sign in with the username and password from the App environment. On the Overview page, you’ll see the RabbitMQ version, memory usage, and the number of connections and queues.
Info: Change the password later

RabbitMQ creates the admin account only when it starts for the very first time. Changes made later in App environment no longer take effect. Change passwords in the management interface under Admin > Users > click the user > Update this user.

How Your Programs Connect to RabbitMQ

The app’s domain only leads to the management interface. Programs connect over AMQP, which is not HTTP. This means AMQP connections don’t use the domain; they connect directly to your VPS IP address and port 5672, as shown on the app card under Connection. Applications on the same VPS, such as another One-Click App, use the same address.

Warning: Port 5672 is accessible from the internet

The One-Click App opens AMQP port 5672 on all addresses of your VPS. No one can log in without valid credentials, but anyone can find the port and try passwords. In addition, AMQP on port 5672 transmits usernames, passwords, and messages without encryption. Only allow connections to the port from the IP addresses your programs actually use.

The easiest way to restrict the port is in the ZapX dashboard. The Network firewall sits in front of your VPS, so it also applies to ports opened by Docker:

  1. Open your VPS and switch to the Network firewall tab.
  2. Add a rule using Add rule: direction Incoming, Action ACCEPT, Protocol tcp, Source your computer or server’s IP address, Destination port 5672.
  3. Add a second rule below it: direction Incoming, Action DROP, Protocol tcp, Destination port 5672, with no source specified.
  4. Check the order: the first matching rule takes precedence. The allow rule must therefore be above the block rule.

For more about rules and IP sets, see Opening ports and managing the firewall on Linux. If you only need to access RabbitMQ occasionally from your own computer, an SSH tunnel is the safest solution: run ssh -L 5672:127.0.0.1:5672 root@SERVER_IP so your program connects securely through localhost:5672.

Updates and backups

Update RabbitMQ in the app settings (gear icon), under App update. Click Check for updates, then install a new version with Apply update. If the page says the app is up to date, there isn’t a newer version in the app catalog yet. The One-Click App uses the official rabbitmq:4-management image, so it stays on RabbitMQ 4.

Users, virtual hosts, queues, and persistently stored messages are kept in the app’s /var/lib/rabbitmq data directory and are retained during updates and restarts. Back up your configuration before an update: open the Overview page in the management interface, expand Export definitions, and click Download broker definitions. The file contains users, virtual hosts, queues, exchanges, and permissions, but not messages. For a full backup, also use your VPS Backups in the dashboard.

Manual Installation

The rest of this guide covers manually installing RabbitMQ with Docker Compose on your VPS. For example, you might choose this option if you don’t use One-Click Apps on the server, need additional plugins such as MQTT, or want to decide for yourself which ports are open to the outside.

Requirements

  • A Linux VPS running Debian or Ubuntu, with SSH access. See First SSH connection.
  • Docker and Docker Compose (Compose v2). See Installing Docker. Check the installation with docker --version and docker compose version.
  • A domain or subdomain whose A record points to your VPS IP address (for example, rabbitmq.example.com) if you want to access the management interface over HTTPS.

RabbitMQ itself is lightweight. The RAM and storage you need depend on how many messages are waiting in queues at the same time:

HardwareMinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM1 GB2 GB
Storage5 GB20 GB

Prepare the Firewall

This guide uses port 5672 for AMQP and port 15672 for the management interface. You’ll access the management interface through a reverse proxy, so only open SSH and the reverse proxy’s ports with ufw:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Warning: Docker bypasses ufw

Ports published by Docker using ports: are accessible from the outside even if ufw blocks them. Docker adds its own rules before those of ufw. Therefore, bind RabbitMQ to 127.0.0.1 as described below and restrict any publicly exposed AMQP port using the Network firewall in the ZapX dashboard. For more information, see Opening ports and managing the firewall on Linux.

Install with Docker Compose

Create a directory for RabbitMQ and generate a password for the admin account. This command writes the password directly to the .env file without displaying it:

Code
mkdir -p /opt/rabbitmq
cd /opt/rabbitmq
echo "RABBITMQ_DEFAULT_PASS=$(openssl rand -hex 24)" >> .env
chmod 600 .env

Then create the docker-compose.yml file, for example by running nano docker-compose.yml, and add this content:

Code
services:
  rabbitmq:
    image: rabbitmq:4-management
    hostname: rabbitmq
    restart: unless-stopped
    environment:
      RABBITMQ_DEFAULT_USER: admin
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
    ports:
      - "127.0.0.1:5672:5672"
      - "127.0.0.1:15672:15672"
    volumes:
      - ./data:/var/lib/rabbitmq
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
      interval: 30s
      timeout: 30s
      retries: 5
      start_period: 60s

Here’s what the important lines do:

  • rabbitmq:4-management: the official image with RabbitMQ 4 and the management interface.
  • hostname: rabbitmq: RabbitMQ stores its data under a node name that includes the hostname. A fixed hostname ensures RabbitMQ can find its data again after the container is recreated.
  • RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS: create the admin account on first startup. This prevents the default guest account from being created.
  • 127.0.0.1:...: AMQP and the management interface are only accessible from the server itself; the interface is accessible from outside only through the reverse proxy.
  • ./data:/var/lib/rabbitmq: users, queues, and persistently stored messages are kept in the /opt/rabbitmq/data directory.
Warning: Never start without your own credentials

If RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS are missing, RabbitMQ creates the guest account with the password guest. Normally, guest can only log in from the server itself, but the official Docker image removes this restriction. If the port is open, RabbitMQ would then be accessible to anyone who knows the default password.

If programs on other servers need to access RabbitMQ, change the AMQP line to "5672:5672" and allow the port in the Network firewall only for their IP addresses, as described above for the One-Click App. Keep in mind that AMQP on port 5672 is unencrypted. For internet connections, RabbitMQ offers AMQP with TLS on port 5671. The official documentation explains how to set it up with your own certificate under TLS Support.

Pull the image and start RabbitMQ:

Code
docker compose pull
docker compose up -d
docker compose logs -f rabbitmq

RabbitMQ is ready when the log shows the line Server startup complete. Exit the log view with Ctrl+C.

First Access

Without a reverse proxy, you can access the management interface through an SSH tunnel. On your own computer, run ssh -L 15672:127.0.0.1:15672 root@SERVER_IP, then open http://localhost:15672 in your browser. Sign in as the user admin. On the server, display the password with grep RABBITMQ_DEFAULT_PASS /opt/rabbitmq/.env.

HTTPS Access Through a Reverse Proxy

For ongoing access to the management interface, put a reverse proxy with a valid certificate in front of it. For the basics, see Setting up a reverse proxy with nginx and Creating an SSL certificate (Let's Encrypt). Here’s a server block for nginx:

Code
server {
    listen 80;
    server_name rabbitmq.example.com;

    location / {
        proxy_pass http://127.0.0.1:15672;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then get the certificate with certbot --nginx -d rabbitmq.example.com. Certbot adds HTTPS and HTTP redirection to the block. Don’t add a path such as / after proxy_pass. Otherwise, nginx converts %2F in the interface’s URLs to /, and pages for the virtual host / will no longer work.

The reverse proxy doesn’t forward AMQP connections; they continue to connect directly through port 5672. For more tips, see Linux security tips.

Back Up Your Data

RabbitMQ distinguishes between two types of data: definitions (users, virtual hosts, queues, exchanges, and permissions) and messages. You can back up definitions while RabbitMQ is running:

Code
cd /opt/rabbitmq
docker compose exec rabbitmq rabbitmqctl export_definitions /var/lib/rabbitmq/definitions.json
cp data/definitions.json rabbitmq-definitions-$(date +%F).json

Use rabbitmqctl import_definitions to restore the file on a new installation. If you also want to back up messages, stop RabbitMQ with docker compose stop and copy the entire /opt/rabbitmq/data directory. Also back up the .env and docker-compose.yml files, and keep the backup somewhere other than the VPS itself.

Update RabbitMQ

With the 4-management tag, docker compose pull gets the latest version of RabbitMQ 4. Enable all feature flags before updating, because RabbitMQ requires the feature flags of the running version to be enabled for new versions:

Code
cd /opt/rabbitmq
docker compose exec rabbitmq rabbitmqctl enable_feature_flag all
docker compose pull
docker compose up -d

Before major version upgrades, read the Release Notes and the Upgrade guidance. You’ll only switch to a new major version, such as RabbitMQ 5, after changing the tag in the docker-compose.yml yourself. The management interface displays the installed version at the top next to the logo.

Set Up and Test Your First Queue

Once RabbitMQ is set up, create a dedicated space for your application and send your first messages through a queue. These steps apply to both the One-Click App and the manual installation.

Create a Virtual Host and User

A virtual host (vHost) is an isolated area in RabbitMQ with its own queues, exchanges, and permissions. Give each application its own vHost and user, with access restricted to that vHost:

  1. In the management interface, open Admin > Virtual Hosts, expand Add a new virtual host, enter a name such as app under Name, and click Add virtual host.
  2. Go to Admin > Users and expand Add a user. Enter app under Username, enter a long password twice, and leave Tags empty. Click Add user.
  3. Click the new app user in the list. Under Set permission, select the app vHost for Virtual Host, leave the three fields set to .*, and click Set permission.

Without a tag, the app user cannot log in to the management interface and can only connect over AMQP. That’s the right setup for an application. You can also perform the same steps from the console, for example with the manual installation. rabbitmqctl prompts you for the password without displaying it:

Code
docker compose exec rabbitmq rabbitmqctl add_vhost app
docker compose exec rabbitmq rabbitmqctl add_user app
docker compose exec rabbitmq rabbitmqctl set_permissions -p app app ".*" ".*" ".*"

Send and Receive Messages with Python

For this test, you’ll need Python 3 on the computer you’re connecting from, as well as the pika library. See Installing Python for instructions on setting up Python. Install pika with:

Code
pip install pika

Create a send.py file. Replace SERVER_IP with your VPS IP address and APP_PASSWORD with the password for the app user:

Code
import pika

credentials = pika.PlainCredentials("app", "APP_PASSWORD")
parameters = pika.ConnectionParameters(host="SERVER_IP", port=5672, virtual_host="app", credentials=credentials)

connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue="tasks", durable=True)

channel.basic_publish(
    exchange="",
    routing_key="tasks",
    body="Hello RabbitMQ",
    properties=pika.BasicProperties(delivery_mode=pika.DeliveryMode.Persistent),
)
print("Message sent")
connection.close()

The script creates the tasks queue if needed and sends a message to it. durable=True and Persistent ensure both survive a RabbitMQ restart. Next, create a receive.py file:

Code
import pika

credentials = pika.PlainCredentials("app", "APP_PASSWORD")
parameters = pika.ConnectionParameters(host="SERVER_IP", port=5672, virtual_host="app", credentials=credentials)

connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue="tasks", durable=True)

def handle(ch, method, properties, body):
    print("Received:", body.decode())
    ch.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_qos(prefetch_count=1)
channel.basic_consume(queue="tasks", on_message_callback=handle)
print("Waiting for messages, press Ctrl+C to exit")
channel.start_consuming()

Run python3 send.py a few times first. In the management interface, under Queues and Streams, you’ll see the tasks queue with the number of waiting messages in the Ready column. Then run python3 receive.py: the script prints the messages and acknowledges each one with basic_ack. RabbitMQ only removes a message from the queue after it’s acknowledged. If the recipient exits before then, another recipient gets the message. With prefetch_count=1, each recipient gets only one message at a time, so the work is distributed when you run receive.py multiple times.

Newer versions of pika show a DeprecationWarning for BlockingConnection, but the examples still work. If the script reports ACCESS_REFUSED, the username or password is incorrect, or the user doesn’t have permission to access the app vHost. If the connection times out, a firewall is blocking port 5672 for your IP address.

Connect Other Applications

Most libraries and programs accept a connection URL. For the user and vHost in this example, it’s:

Code
amqp://app:APP_PASSWORD@SERVER_IP:5672/app

The part after the last / is the vHost; write the default vHost / as %2F. Special characters such as @ or / in a password must be encoded in the URL. It’s easier to use a password made up of letters and numbers only. In n8n, enter the same details in the RabbitMQ credentials under Hostname, Port, User, Password, and Vhost. Celery expects the URL as broker_url.

Monitor RabbitMQ

The Overview page shows how much RAM and storage RabbitMQ is using and where the limits are under Nodes. Under Queues and Streams, you can see the messages waiting in each queue (Ready) and those currently being processed (Unacked). If Ready keeps growing, your recipients can’t keep up.

For automated monitoring, the management interface provides an HTTP API. This request returns {"status":"ok"} as long as there is no RAM or storage alarm:

Code
curl -u USERNAME:PASSWORD https://rabbitmq.example.com/api/health/checks/alarms

Use a dedicated user with the Monitoring tag for this. For example, you can add this address to Uptime Kuma as an HTTP monitor with Basic Auth. With a manual installation, you can also check the status in the console using docker compose exec rabbitmq rabbitmq-diagnostics -q check_local_alarms.

Limitations

  • RAM and storage alarms: If RabbitMQ uses 60% of the RAM or storage space is running low, it stops accepting new messages until space is available again. Senders will then hang. Make sure recipients process the queues and plan for enough storage.
  • AMQP only in the One-Click App: The One-Click App only opens the port for AMQP. MQTT, STOMP, or RabbitMQ Streams require additional plugins and ports. Use the manual installation for these.
  • No TLS by default: AMQP on port 5672 is unencrypted. For internet connections, use an SSH tunnel, a VPN, or AMQP with TLS on port 5671 with a manual installation.
  • Single server: If the VPS goes down, RabbitMQ is unavailable. High availability with multiple nodes and quorum queues isn’t possible with a single VPS.
  • Not for long-term storage: RabbitMQ forwards messages quickly. Keeping large quantities in queues for a long time uses a lot of RAM and storage.

Conclusion

You’ve set up RabbitMQ on your VPS, restricted the AMQP port to your own IP addresses, created a dedicated virtual host and user, and sent and received your first messages with Python. Your applications can now reliably exchange tasks and events through RabbitMQ.

Prefer not to manage Docker yourself? Choose the easy One-Click App option described above under “The Easy Way: RabbitMQ as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the fastest option: RabbitMQ is running within one to two minutes, the management interface is available over HTTPS on your domain, the admin account is generated automatically, and you can install updates in the dashboard. A manual installation with Docker Compose is a good choice if you don’t use One-Click Apps on the server, need plugins such as MQTT or STOMP, want to set up AMQP with TLS, or want to choose which ports are open to the outside.
For the One-Click App, click the gear icon on the app card and open App environment. Under Automatically generated values, you’ll find SERVICE_USER_RABBITMQ (username) and SERVICE_PASSWORD_RABBITMQ (password). Use these to sign in to the management interface through the Access link. You can then create dedicated users with limited permissions for your applications.
RabbitMQ only creates the default guest account if you don’t set your own credentials on first startup. The One-Click App generates a dedicated admin account instead, so guest isn’t available there. Also, RabbitMQ normally only allows guest to log in from the server itself. Use the credentials shown in App environment.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.