Self-hosting

RabbitMQ on a VPS: message queues for your applications

A page that generates an invoice, sends three emails and resizes a photo before answering always ends up timing out at the worst moment. The classic fix is to hand those tasks to a message queue: the application drops the work, workers process it in the background, and nothing is lost if one of them crashes. RabbitMQ is the most widely used open-source message broker for the job. This guide installs it on a VPS with Docker Compose, publishes its management console over HTTPS behind nginx, keeps the AMQP port private and connects Laravel, Django or Node.js to it.

Deploy on a VPS Cloud →
7 min read4 steps

Orbi AI agentThe contents follow the article; related articles wait at the bottom.

Contents· What RabbitMQ does1/12
  1. 01What RabbitMQ does
  2. 02What RabbitMQ gives you
  3. 03Redis, RabbitMQ or Kafka for your messages
  4. 04Prepare the server
  5. 05Install RabbitMQ with Docker Compose
  6. 06Keep AMQP private and one user per application
  7. 07Publish the console over HTTPS behind nginx
  8. 08Create one vhost and one user per application
  9. 09Connect Laravel, Django or Node.js
  10. 10Watch the queues
  11. 11Backup and upgrade
  12. 12RabbitMQ in one click on ServOrbit

What RabbitMQ does

RabbitMQ is an open-source message broker (MPL-2.0 licence) written in Erlang. Applications send it messages over the AMQP protocol; it stores them in queues, keeps them on disk when asked to, and hands them to consumers that acknowledge them once processed. An unacknowledged message — because the worker crashed — is redelivered to another one. Between the application and the queues, exchanges route each message to one queue, several, or every queue subscribed to it.

What RabbitMQ gives you

  • Pages that answer fast — slow tasks go to a queue instead of blocking the request.
  • No lost jobs — durable queues and acknowledgements: a crashing worker makes nothing disappear.
  • Spikes absorbed — messages wait in the queue while workers catch up.
  • Decoupled services — an event published once, received by every service that needs it.
  • A web console — queues, rates, consumers and pending messages at a glance.
  • Every language — PHP, Python, Java, Node.js, .NET, Go and Ruby all have an AMQP client.

Redis, RabbitMQ or Kafka for your messages

Scroll the table

Redis (list or stream)RabbitMQKafka
Typical useCache, small job queueJob queues and event routingVery high-volume event log
Acknowledgement and redeliveryHandled in the applicationBuilt inThrough read offsets
RoutingSimpleDirect, topic, fanout, headers exchangesBy topic and partition
Management consoleNone out of the boxIncluded (management plugin)Third-party tools
Memory at restA few MBAbout 150 MBOften more than 1 GB

Prepare the server

An Ubuntu 24.04 VPS with 2 GB of RAM suits most projects: RabbitMQ uses about 150 MB at rest, and it often shares the machine with the application and its workers. Install Docker and the Compose plugin, and plan a subdomain, for example rabbitmq.example.com, pointing to the VPS: the management console must be served over HTTPS, since passwords travel through it. The AMQP port will never be published to the Internet.

Install RabbitMQ with Docker Compose

  1. Prepare the folder and the .env file

    A single secret: the password of the admin account, created on first start.

    mkdir -p /opt/rabbitmq && cd /opt/rabbitmq
    cat > .env <<EOF
    RABBITMQ_PASSWORD=$(openssl rand -hex 16)
    EOF
    chmod 600 .env
  2. Write the docker-compose.yml file

    A single service, the official image with the management console. Both ports are only published on the loopback: the console (15672) will go through nginx, and AMQP (5672) stays reserved for the VPS. The fixed hostname matters: RabbitMQ stores its data under its node name, and a container recreated under another name would start from an empty database.

    services:
      rabbitmq:
        image: rabbitmq:4.4-management-alpine
        hostname: rabbitmq
        restart: unless-stopped
        ports:
          - "127.0.0.1:15672:15672"
          - "127.0.0.1:5672:5672"
        environment:
          RABBITMQ_DEFAULT_USER: admin
          RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
        volumes:
          - rabbitmq-data:/var/lib/rabbitmq
        networks:
          - rabbitmq
        healthcheck:
          test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"]
          interval: 30s
          timeout: 10s
          retries: 5
    networks:
      rabbitmq:
        name: rabbitmq
    volumes:
      rabbitmq-data: {}
  3. Start and check

    RabbitMQ answers in about fifteen seconds. The console API must return 200 with the admin account, and 401 without it.

    docker compose up -d
    docker compose ps
    curl -s -o /dev/null -w '%{http_code}\n' -u admin:"$(grep RABBITMQ_PASSWORD .env | cut -d= -f2)" \
      http://127.0.0.1:15672/api/overview
  4. Check the account and the node

    Only admin should be listed: as soon as RABBITMQ_DEFAULT_USER is set, the factory guest account is not created.

    docker compose exec rabbitmq rabbitmqctl list_users
    docker compose exec rabbitmq rabbitmq-diagnostics status | head -n 20

Keep AMQP private and one user per application

Never publish port 5672 on 0.0.0.0: your applications reach it through the loopback or the Docker network, and an exposed broker attracts login attempts. And never give the admin account to an application: create its own vhost and user (next section), so that a leak stays confined to its space.

Publish the console over HTTPS behind nginx

Get a certificate with certbot (certbot certonly --nginx -d rabbitmq.example.com), then declare a server block that forwards to local port 15672. The console and its API share the same address.

server {
    listen 443 ssl;
    server_name rabbitmq.example.com;
    ssl_certificate     /etc/letsencrypt/live/rabbitmq.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/rabbitmq.example.com/privkey.pem;
    location / {
        proxy_pass http://127.0.0.1:15672;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
    }
}

Create one vhost and one user per application

A virtual host is a sealed space: its queues, exchanges and permissions see nothing of the others. Create one per application, with a user that only has permissions on it. The same can be done in the Admin tab of the console.

docker compose exec rabbitmq rabbitmqctl add_vhost shop
docker compose exec rabbitmq rabbitmqctl add_user app-shop '<long-password>'
docker compose exec rabbitmq rabbitmqctl set_permissions -p shop app-shop ".*" ".*" ".*"
docker compose exec rabbitmq rabbitmqctl list_permissions -p shop

Connect Laravel, Django or Node.js

An application installed directly on the VPS connects to 127.0.0.1:5672. For Laravel, the laravel-queue-rabbitmq package adds a queue driver; php artisan queue:work rabbitmq then starts the workers.

composer require vladimir-yuldashev/laravel-queue-rabbitmq

# application .env
QUEUE_CONNECTION=rabbitmq
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USER=app-shop
RABBITMQ_PASSWORD=<long-password>
RABBITMQ_VHOST=shop

Celery, with Django or on its own, takes an AMQP URL. An application running in a container joins the rabbitmq network and targets the service name instead of 127.0.0.1. Node.js (amqplib), Spring AMQP or .NET accept the same URL.

# settings.py (Django + Celery)
CELERY_BROKER_URL = "amqp://app-shop:<long-password>@127.0.0.1:5672/shop"

# containerised application: join the RabbitMQ network
docker network connect rabbitmq my-worker
# then amqp://app-shop:<long-password>@rabbitmq:5672/shop

Watch the queues

A queue that keeps growing signals workers that are too slow or stopped. The console shows it in the Queues tab; on the command line, the same reading fits in one line: ready messages, messages being processed and number of consumers per queue.

docker compose exec rabbitmq rabbitmqctl list_queues name messages_ready messages_unacknowledged consumers

For long-term monitoring, the rabbitmq_prometheus plugin is already enabled in the official image: it serves its metrics on port 15692 of the container. Publish it as 127.0.0.1:15692:15692 and add it to the Prometheus targets to follow the queues in Grafana.

Backup and upgrade

The whole state of RabbitMQ lives in the rabbitmq-data volume. Also export its definitions — users, vhosts, queues, exchanges and permissions — to a JSON file: that is what rebuilds a broker in seconds, with rabbitmqctl import_definitions.

cd /opt/rabbitmq
docker compose exec rabbitmq rabbitmqctl export_definitions /tmp/definitions.json
docker compose cp rabbitmq:/tmp/definitions.json ./definitions-$(date +%F).json

Before moving to a new series, enable the feature flags of the running version, read the release notes, then change the image tag and restart:

docker compose exec rabbitmq rabbitmqctl enable_feature_flag all
docker compose pull && docker compose up -d

RabbitMQ in one click on ServOrbit

The ServOrbit Marketplace installs exactly this stack: the official rabbitmq image with its console, an admin account created with a generated password, the console published over HTTPS on a subdomain of your domain or on the VPS's free subdomain, and the AMQP port kept on the loopback. The password is shown in your client area; all that is left is to create your vhosts and connect your workers.

Share this articleservorbit.com/ma-en/blog/self-host-rabbitmq-vps-message-broker

Reliable message queues for your applications

Prices shown excluding VAT, with their renewal price.