This repository contains a reverse proxy server implementation built with Go. The server supports HTTP and HTTPS protocols and allows multiple route configuration through a YAML file. Each route runs on seperate go routine allowing port based routing.It also includes Docker support for containerized deployment.
- Reverse proxy server with HTTP and HTTPS support.
- Route configuration using a YAML file.
- CORS header support for cross-origin requests.
- TLS configuration for HTTPS routes.
- Error logging and handling.
- Support for multiple routes, each running in a separate goroutine.
To run this project, you'll need:
- Go 1.22 or above
- Docker (optional, for containerized execution)
- Docker Compose (optional, for multi-container orchestration)
-
Clone the repository:
git clone <repository-url> cd reverseproxy
-
Download the Go modules:
go mod download
-
Build the project:
go build -o reverseproxy ./cmd/main.go
The reverse proxy is configured using a YAML file located at config/config.yaml
. Below is an example configuration:
routes:
- name: "grafana"
listenHost: "0.0.0.0"
listenport: 6442
protocol: "http"
certFile: "/path/to/certfile.crt"
keyFile: "/path/to/keyfile.key"
pattern: "/"
target:
name: "grafana-service"
protocol: "http"
host: "192.168.1.100"
port: 3000
certfile: "/path/to/target/certfile.crt"
keyfile: "/path/to/target/keyfile.key"
To run the reverse proxy server:
- Ensure the configuration file is properly set up.
- Execute the server:
./reverseproxy
By default, the server will load configuration from config/config.yaml
, validate routes, and start the proxy for each route defined. Each route will run in a separate goroutine for concurrent request handling.
- Build the Docker image:
docker build -t reverseproxy .
- Run the container:
docker run -p 8080:8080 reverseproxy
You can adjust the port and other environment variables as needed. The Dockerfile also supports non-root user setup and signal handling with tini
.
For multi-container orchestration, you can use Docker Compose.
-
Ensure you have a
docker-compose.yml
file setup. Example:version: '3' services: reverseproxy: build: . ports: - "8080:8080" environment: - CONFIG_FILE=/config/config.yaml - LOG_LEVEL=info volumes: - ./config/config.yaml:/config/config.yaml
-
Build and run the services:
docker compose up --build # or without .env file docker-compose up --build \ --build-arg TARGETOS=linux \ --build-arg TARGETARCH=amd64 \ --build-arg CA_CERT_PATH=/path/to/ca.crt \ --build-arg CONFIG_FILE=/path/to/config.yaml
This will build the Docker image and start the container as specified in your docker-compose.yml
file.
Adjust the configuration file path, environment variables, and other settings as needed.
Each route will run in a separate goroutine for concurrent request handling. Add the listen ports to docker ports
section to expose the services to the host machine.
We welcome contributions! Please open an issue or submit a pull request for any improvements or bug fixes.
Run the tests using the following command:
go test ./...
Ensure all tests pass before submitting a pull request.
This project is licensed under the MIT License. See the LICENSE
file for more details.
For more information or support, please contact [your contact email].