How to Change RabbitMQ Port and Set Up a Reverse Proxy with Nginx

RabbitMQ is a powerful message broker that supports various messaging protocols. By default, RabbitMQ listens on port 5672 for AMQP and 15672 for HTTP management UI. However, there are situations where you might want to change these ports or set up a reverse proxy using Nginx for enhanced security or easier access. This guide will walk you through the process.

Changing RabbitMQ Ports

To change the default ports used by RabbitMQ, you need to modify the RabbitMQ configuration file.

Locate the RabbitMQ Configuration File

RabbitMQ configuration can be managed using its configuration file (rabbitmq.conf) or the advanced configuration file (advanced.config). The default location of these files depends on your operating system:

  • Linux: /etc/rabbitmq/rabbitmq.conf
  • Windows: %APPDATA%\RabbitMQ\rabbitmq.conf

If the file doesn’t exist, you may need to create it.

Modify the Configuration File

To change the default ports, add the following entries to rabbitmq.conf:

listeners.tcp.default = 5673
management.listener.port = 15673
    

Here:

  • listeners.tcp.default changes the AMQP port.
  • management.listener.port changes the HTTP management UI port.

Restart RabbitMQ

After saving the configuration file, restart RabbitMQ to apply the changes:

sudo systemctl restart rabbitmq-server
    

Or, if you’re using Windows:

rabbitmq-service stop
rabbitmq-service start
    

Setting Up a Reverse Proxy with Nginx

Reverse proxies improve security, load balancing, and ease of access. With Nginx, you can configure RabbitMQ’s ports to be accessible through standard HTTP or HTTPS ports (80/443).

Install Nginx

Install Nginx if it’s not already installed:

  • On Ubuntu/Debian:
    sudo apt update && sudo apt install nginx
  • On CentOS/RHEL:
    sudo yum install nginx

Configure Nginx for RabbitMQ

Edit or create a new configuration file for RabbitMQ under /etc/nginx/sites-available/ or /etc/nginx/conf.d/.

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-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 443 ssl;
    server_name rabbitmq.example.com;

    ssl_certificate /path/to/ssl/certificate.crt;
    ssl_certificate_key /path/to/ssl/private.key;

    location / {
        proxy_pass http://127.0.0.1:15672;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
    

Enable the Nginx Configuration

For sites-available setups:

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

Test the configuration:

sudo nginx -t
    

Reload Nginx:

sudo systemctl reload nginx
    

Testing Your Setup

To test if everything is set up correctly:

  • For HTTP: http://rabbitmq.example.com
  • For HTTPS: https://rabbitmq.example.com

Verify port changes by using netstat or ss:

sudo netstat -tuln | grep 5673
    

Conclusion

By changing the RabbitMQ ports and setting up a reverse proxy with Nginx, you can better secure and optimize access to RabbitMQ services. This setup is particularly useful in production environments where security and scalability are critical.


How to Apply Ubuntu Updates Safely and Efficiently

Keeping your Ubuntu system up to date ensures it stays secure, stable, and equipped with the latest features. Here is a step-by-step guide to applying updates safely and efficiently on your Ubuntu system.

Why Updates Are Important

Ubuntu updates typically include security patches, software bug fixes, performance improvements, and occasionally, new features. Regularly updating your system reduces vulnerabilities and ensures smooth operation.

Step 1: Check for Available Updates

Before applying updates, you should check which ones are available. Open a terminal and run the following command:

sudo apt update

This command refreshes the list of available packages and updates your local package index. It does not install any updates yet.

Step 2: Review Available Updates

To view the list of packages with available updates, run:

apt list --upgradable

This step allows you to review updates and decide whether to proceed with all of them or select specific ones.

Step 3: Install Updates

To install all available updates, use the following command:

sudo apt upgrade

This command upgrades all packages that can be updated without altering the current dependencies or removing existing packages.

Step 4: Full System Upgrade (Optional)

In some cases, updates might require changing dependencies or installing/removing packages. To perform a full system upgrade, run:

sudo apt full-upgrade

This command applies all updates, even if it requires changing the system’s package structure. Use it cautiously and review changes before confirming.

Step 5: Clean Up Unnecessary Packages

After applying updates, you can remove unnecessary packages to free up space:

sudo apt autoremove

This command removes unused dependencies left behind by package updates or removals.

Step 6: Reboot (If Required)

Certain updates, such as kernel updates, require a system reboot to take effect. If prompted, restart your system:

sudo reboot

Alternatively, you can check if a reboot is required by running:

dpkg --get-selections | grep linux-image

Best Practices for Updating Ubuntu

  • Backup Critical Data: Before applying updates, especially major ones, back up your important files.
  • Update Regularly: To avoid accumulating a large number of updates, check for and apply updates weekly.
  • Use Long-Term Support (LTS) Versions: If stability is a priority, stick to LTS versions of Ubuntu, as they receive extended support.

By following these steps, you can ensure that your Ubuntu system stays updated without unnecessary risks. Regular maintenance helps maintain security, performance, and compatibility with modern applications.