How to Deploy Nginx Proxy Manager with Ansible and Docker: A Step-by-Step Guide
Managing web traffic is like directing a busy airport—Nginx Proxy Manager makes it simple to route requests, secure connections, and manage SSL certificates. This guide shows you how to automate the deployment of Nginx Proxy Manager in a Docker container using Ansible, ensuring a secure and efficient setup. Perfect for IT admins and DevOps teams, this process streamlines proxy management for your applications. Let’s get your server ready to handle web traffic like a pro!
Why Use Nginx Proxy Manager with Ansible and Docker?
Nginx Proxy Manager offers a user-friendly interface to manage reverse proxies, SSL certificates, and domain routing. Running it in Docker ensures a lightweight, portable setup, while Ansible automates the entire process, from server configuration to firewall rules. Think of it as setting up a smart traffic control system with minimal effort. This approach is ideal for businesses needing secure, scalable web management.
Prerequisites for a Smooth Deployment
Before starting, ensure you have:
- Ansible 2.9+ installed on your control node.
- SSH access to a Linux server (e.g., Ubuntu, CentOS) with internet access.
- A domain name or IP address for accessing Nginx Proxy Manager.
- A MySQL-compatible database (configured automatically by the playbook).
Quick Tip: Verify SSH connectivity and ensure your server has internet access to avoid deployment hiccups.
Step-by-Step Guide to Deploy Nginx Proxy Manager
Follow these steps to automate your Nginx Proxy Manager setup using the Ansible Nginx Proxy Manager repository.
1. Clone the Ansible Repository
Start by downloading the playbook from GitHub:
git clone https://github.com/Shipssv83/Ansible-Nginx-Proxy-Manager.git
cd Ansible-Nginx-Proxy-Manager
This repository includes all the playbooks and roles needed for a complete setup.
2. Install Ansible Galaxy Roles
Install the required roles to support your playbooks:
ansible-galaxy install -r roles/requirements.yml
To update existing roles, run:
ansible-galaxy install -g -f -r roles/requirements.yml
These roles handle server setup, Docker installation, and Nginx Proxy Manager configuration.
3. Configure the Inventory File
Create an inventory file to specify your target server:
vim inventory
Add your server details, for example:
[servers]
192.168.1.100 ansible_user=root
Replace 192.168.1.100 with your server’s IP and root with your SSH user.
4. Customize Playbook Variables
Tailor the deployment by editing key variables in your playbook:
vars:
email: "admin@example.com"
nginx_mysql_pass_web: "changeme"
nginx_pm_host_name: "proxy.example.com"
nginx_mysql_user: "nginx_user"
nginx_mysql_pass: "secure_password"
nginx_mysql_name: "nginx_db"
nginx_mysql_root_pass: "root_password"
your_ip: "192.168.1.100"
What do these do?
email: Admin email for Nginx Proxy Manager login.nginx_pm_host_name: Domain or hostname for accessing the proxy manager.nginx_mysql_userandnginx_mysql_pass: Credentials for the MySQL database.your_ip: IP address allowed to access the server via UFW.
5. Configure the Server Environment
Run the server setup playbook to prepare the environment:
ansible-playbook -i inventory --user root --extra-vars "host=servers" playbooks/server-install.yml
This playbook installs essential packages and sets the server’s timezone.
6. Install Docker and Docker Compose
Deploy Docker with this playbook:
ansible-playbook -i inventory --user root --extra-vars "host=servers" playbooks/docker-install.yml
This sets up Docker and Docker Compose, creating a foundation for running containers.
7. Deploy Nginx Proxy Manager in Docker
Launch Nginx Proxy Manager with the final playbook:
ansible-playbook -i inventory --user root --extra-vars "host=servers" playbooks/nginx-pm-docker-install.yml
This playbook:
- Pulls the Nginx Proxy Manager Docker image.
- Configures the web interface and MySQL database.
- Sets up UFW firewall rules for secure access.
Accessing Nginx Proxy Manager
Once deployed, access Nginx Proxy Manager at:
http://<your-server-ip>:81
Login Credentials:
- Email:
admin@example.com - Password:
changeme
Important: Change the default admin password immediately after logging in to secure your system.
Configuring Proxy Hosts
To route traffic:
- Log in to Nginx Proxy Manager.
- Add a new proxy host under the “Hosts” tab.
- Enter your domain, target IP, and port (e.g., for a web app).
- Enable SSL for secure connections using Let’s Encrypt.
Benefits of This Setup
This deployment offers:
- Automation: Ansible streamlines setup, reducing errors.
- User-Friendly: Nginx Proxy Manager’s interface simplifies proxy management.
- Security: UFW and MySQL configurations protect your server.
- Scalability: Docker makes it easy to scale or replicate your setup.
It’s like building a smart traffic hub that directs web requests with ease and security.
Troubleshooting Tips
If issues arise:
- Check Playbook Logs: Review Ansible output for errors.
- Verify Docker Containers: Use
docker psto confirm Nginx Proxy Manager is running. - Inspect Firewall Rules: Ensure UFW allows ports 80, 443, and 81.
- Test Database Settings: Confirm MySQL credentials match your playbook variables.
Conclusion: Simplify Web Management with Nginx Proxy Manager
With Nginx Proxy Manager, Ansible, and Docker, you’ve created a powerful, automated solution for managing web traffic and SSL certificates. Your server is now ready to handle proxy hosts and secure connections effortlessly. Want more IT automation tips? Visit blog.1it.pro or share your setup on 1it.pro to inspire the community!
🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.