In modern web development, using a combination of different technologies can significantly enhance performance and security. This blog post will guide you through the process of setting up Apache2 as a web server on your host machine, while utilizing Nginx Proxy Manager (NPM) in Docker for managing reverse proxy and SSL termination.
Why Use Nginx Proxy Manager with Apache?
Nginx Proxy Manager provides a user-friendly interface for managing your reverse proxy settings, including SSL certificates, which makes it a great addition to your setup. By placing NPM in front of Apache, you can easily handle HTTPS connections and route traffic to multiple applications running on your server.
Prerequisites
- A Debian/Ubuntu server with Docker and Docker Compose installed.
- Apache2 installed and running on the host server.
- Basic understanding of Docker and command-line interface.
Step 1: Setting Up Nginx Proxy Manager in Docker
First, create a docker-compose.yml file for Nginx Proxy Manager:
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '81:80' # Public HTTP Port for NPM
- '443:443' # Public HTTPS Port for NPM
- '82:81' # Admin Web Port
environment:
DB_SQLITE_FILE: "/data/database.sqlite"
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
networks:
nginx-network:
driver: bridge
Run the following command to start NPM:
docker compose up -d
Step 2: Configure Apache2 on the Host Server
Modify ports.conf to Listen on Port 8080:
Open the ports.conf file to add port 8080:
sudo nano /etc/apache2/ports.conf
Add the following line if it doesn’t already exist:
Listen 8080
Create a Virtual Host Configuration:
Create a new configuration file for your WordPress site. For example, if your WordPress site is located in /var/www/html/wordpress, create a configuration file:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following configuration:
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/html/wordpress
<Directory /var/www/html/wordpress>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
Enable the Site and Required Modules:
Run the following commands to enable the new site and the rewrite module:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl reload apache2 && sudo systemctl restart apache2
Step 3: Set Up Proxy Host in Nginx Proxy Manager
1. Access the NPM Admin Interface:
Visit http://<your-server-ip>:82 and log in.
2. Add a Proxy Host:
Click on Proxy Hosts and then Add Proxy Host.
- Domain Names: example.com
- Forward Hostname / IP: localhost
- Forward Port: 8080
- Enable Block Common Exploits.
- Enable Websocket Support if necessary.
3. Configure SSL Settings:
Enable SSL, choose Let's Encrypt, and provide your email address for notifications.
Click Save.
With this setup, Nginx Proxy Manager will handle HTTPS requests to your domain, while forwarding traffic to the Apache server running on port 8080. This allows you to benefit from Apache's robust features while taking advantage of NPM's easy SSL management.
By using Nginx Proxy Manager, you streamline your server management and enhance the security of your web applications. Now, you can focus on developing your applications without worrying about the complexities of SSL and reverse proxy configurations.