This project demonstrates how to set up a reverse proxy using Nginx with Docker Compose, implementing host-based routing for multiple applications.
.
├── docker-compose.yaml # Docker Compose configuration
├── nginx.conf # Nginx proxy configuration
├── readme.md
├── start.sh
├── app1/ # First Python application
│ ├── Dockerfile
│ ├── main.py
│ └── requirements.txt
└── app2/ # Second Python application
├── Dockerfile
├── main.py
└── requirements.txt
- Host-based routing using Nginx
- Multiple Python applications running in separate containers
- Docker Compose for container orchestration
- Custom network configuration
- Volume mounting for Nginx configuration
- Docker
- Docker Compose
- Basic understanding of Nginx configuration
- Clone this repository
- Add the following entries to your
/etc/hostsfile:127.0.0.1 app1.localhost 127.0.0.1 app2.localhost - Make the start script executable:
chmod +x start.sh
- Run the start script to build and start all services:
./start.sh
The start script will:
- Build the Docker images for both applications
- Stop any existing containers (if running)
- Start all services using Docker Compose
Alternatively, you can manually run the services:
docker compose up -d- App1: http://app1.localhost:8080
- App2: http://app2.localhost:8080
The Nginx configuration implements host-based routing, directing traffic based on the domain name:
- Requests to
app1.localhostare routed to the app1 container - Requests to
app2.localhostare routed to the app2 container
The project uses Docker Compose to manage:
- Three containers: app1, app2, and nginx-proxy
- A custom network for container communication
- Port mapping (8080:80) for the Nginx proxy
- Volume mounting for the Nginx configuration
If you cannot access the applications:
- Verify that all containers are running:
docker compose ps - Check the Nginx logs:
docker compose logs nginx-proxy - Ensure the host entries are properly configured
- Verify that port 8080 is not in use by another application
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License.