Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Subdomain Reverse Proxy

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.

What's this all about?

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

Getting Started

Prerequisites

  • Docker
  • Docker Compose
  • Domain name with ability to create subdomains
  • Backend services to proxy to

Quick Setup

  1. Clone this repository:

    git clone https://github.com/Cedric-Froehner/subdomain-reverse-proxy.git
    cd subdomain-reverse-proxy
  2. Edit the nginx.conf file to configure your subdomains and backend services:

    server {
      server_name your-subdomain.example.com;
      location / {
        proxy_pass http://your-backend-service:port;
      }
    }
  3. Start the server:

    docker-compose up -d

That's it! Your reverse proxy is now running and will route traffic based on the subdomain.

Configuration

File Structure

subdomain-reverse-proxy/
├── docker-compose.yml  # Docker configuration
├── nginx.conf         # Nginx server configuration
└── README.md         # This documentation

Port Configuration

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 -d

Multiple Server Blocks

You 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;
  }
}

Security Notes

  • 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

Using with Document Provider

This reverse proxy works great with document-provider to serve your protected documents through different subdomains. Here's how to set it up:

  1. First, set up your document-provider instance following its documentation. Note the port it's running on (default: 8080).

  2. 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!

Contributing

Got ideas to make this better? Awesome! Feel free to:

  1. Fork the repository
  2. Create your feature branch
  3. Make your changes
  4. Submit a pull request

Need Help?

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

License

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.

About

This simple Docker-based reverse proxy can be used to forward subdomains to specific webservers or subsites.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors