Hey there! Welcome to the Subdomain Reverse Proxy repository. This is a super simple yet flexible way to set up subdomain-based reverse proxying using Nginx and Docker. It's designed to be lightweight, secure, and easy to deploy.
This repository sets up a reverse proxy server where you can:
- Redirect subdomains to different backend services
- Configure multiple server blocks with different routing rules
- Run everything in a Docker container for easy deployment
- Handle HTTP traffic with potential for SSL/TLS configuration
- Docker
- Docker Compose
- Domain name with ability to create subdomains
- Backend services to proxy to
-
Clone this repository:
git clone https://github.com/Cedric-Froehner/subdomain-reverse-proxy.git cd subdomain-reverse-proxy -
Edit the
nginx.conffile to configure your subdomains and backend services:server { server_name your-subdomain.example.com; location / { proxy_pass http://your-backend-service:port; } }
-
Start the server:
docker-compose up -d
That's it! Your reverse proxy is now running and will route traffic based on the subdomain.
subdomain-reverse-proxy/
├── docker-compose.yml # Docker configuration
├── nginx.conf # Nginx server configuration
└── README.md # This documentation
By default, the reverse proxy runs on port 80. To change this, edit the port mapping in your docker-compose.yml file:
services:
subdomain-reverse-proxy:
# ... other configuration ...
ports:
- "80:80" # Format is "external_port:internal_port"To use a different port (for example, port 8080), change the external port:
ports:
- "8080:80"After changing the port, restart the container:
docker-compose down
docker-compose up -dYou can configure multiple server blocks for different subdomains. Here's an example:
# Default server block - catches undefined subdomains
server {
server_name _;
location / {
return 404;
}
}
# Specific subdomain configuration
server {
server_name app.example.com;
location / {
proxy_pass http://localhost:3000;
}
}
# Another subdomain
server {
server_name api.example.com;
location / {
proxy_pass http://localhost:8080;
}
}- The configuration file is mounted as read-only in the container
- The server runs in an Alpine-based container for minimal attack surface
- HTTPS is recommended for production use (you'll need to configure SSL certificates)
- Consider implementing rate limiting and other security measures for production
This reverse proxy works great with document-provider to serve your protected documents through different subdomains. Here's how to set it up:
-
First, set up your document-provider instance following its documentation. Note the port it's running on (default: 8080).
-
Add a server block for your documents subdomain in
nginx.conf:server { server_name docs.example.com; location / { proxy_pass http://your-document-provider:8080; } }
It is possible to add both containers to the same docker network to prevent publishing the document-provider directly to the outside world.
Now your documents will be accessible through docs.example.com while still maintaining all the security features of document-provider!
Got ideas to make this better? Awesome! Feel free to:
- Fork the repository
- Create your feature branch
- Make your changes
- Submit a pull request
If you run into any issues or have questions, feel free to:
- Open an issue in this repository
- Check the Nginx documentation for advanced configuration options
- Look into Docker documentation for container-related questions
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses the official Nginx Docker image (nginx:stable-alpine). The Nginx license and any other third-party licenses are handled through their respective Docker images and packages.
Made to make subdomain routing a bit easier.