Skip to content

thiagofeijodev/proxy-frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 Multi-Instance App Routing with Nginx

An Nginx configuration that dynamically routes subdomains to separate instances of the same application, each running on a different port. Ideal for multi-tenant environments, testing, or scaling applications without manual configuration for each subdomain.


πŸ“Œ Features

  • Dynamic Subdomain Routing: Automatically routes subdomains like app1.example.com, app2.example.com, etc., to their respective application instances.
  • Scalable Architecture: Easily scale by adding new application instances and corresponding subdomains without modifying the Nginx configuration.
  • Simplified Management: Manage multiple application instances through a single Nginx configuration, reducing complexity and potential for errors.

βš™οΈ Requirements

  • Nginx
  • Docker (for containerized applications)
  • Application Instances: Ensure each application instance is running on a unique port.

πŸ”§ Environment Variables

Configure the following environment variables:

  • BASE_URL_S3: The base URL for S3 storage (e.g., https://s3.amazonaws.com/your-bucket)
  • BASE_DOMAIN: The base domain for subdomain routing (e.g., example.com)
  • BASE_EXTENSION: The extension or port mapping for application instances (e.g., app, instance)

πŸš€ Setup

1. Clone the Repository

git clone https://github.com/thiagofeijodev/proxy-frontend.git
cd proxy-frontend

2. Set Environment Variables

Create a .env file in the project root or export the variables:

export BASE_URL_S3="https://s3.amazonaws.com/your-bucket"
export BASE_DOMAIN="example.com"
export BASE_EXTENSION="app"

3. Install and Run with Docker

Build the Docker Image

docker build -t proxy-frontend:latest .

Run the Docker Container

docker run -d \
  --name proxy-frontend \
  -p 80:80 \
  -p 443:443 \
  -e BASE_URL_S3="$BASE_URL_S3" \
  -e BASE_DOMAIN="$BASE_DOMAIN" \
  -e BASE_EXTENSION="$BASE_EXTENSION" \
  proxy-frontend:latest

Or using the provided script:

chmod +x init-docker.sh
./init-docker.sh

5. Test Nginx Configuration

docker exec proxy-frontend nginx -t

πŸ› οΈ Customization

Feel free to modify the Nginx configuration to suit your specific needs:

  • SSL/TLS: Add SSL certificates for secure HTTPS connections.
  • Load Balancing: Implement load balancing strategies if needed.
  • Access Control: Set up authentication or IP whitelisting as required.

πŸ“š Resources


πŸ§‘β€πŸ’» Contributing

Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request with your proposed changes.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

🌐 An Nginx configuration that dynamically routes subdomains to separate instances of the same application, each running on a different port. Ideal for multi-tenant environments, testing, or scaling applications without manual configuration for each subdomain.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors