goprivateproxy
A Go-based reverse proxy and AWS PrivateLink replacement running as a systemd service on EC2 instances. Includes rate limiting, bot blocking, and dynamic routing based on subdomains and paths.
Requirements
Features
- Reverse proxy for handling incoming requests
- Rate limiting to prevent abuse
- Bot blocking based on user-agent strings
- Dynamic routing based on subdomains and paths
- Configurable via a YAML configuration file
Installation
-
Clone the repository:
git clone https://github.com/dutchdata/goprivateproxy.git
cd goprivateproxy
-
Create a configuration file:
cp config.yaml.example config.yaml
-
Edit config.yaml according to your subnet and requirements:
The configuration file supports the following fields:
port
: The port on which the proxy server listens.
limiter
: Rate limiting configuration, with rps
(requests per second) and burst
values.
botBlockList
: A list of user-agent substrings to block.
permittedBots
: A list of user-agent substrings to allow.
otherRoutes
: A list of routes for subdomains and paths.
ip
: Target IP address.
port
: Target port.
path
: Path or subdomain for routing.
defaultRoute
: Default route configuration.
ip
: Default target IP address.
port
: Default target port.
Getting Started
Fetch config and create the server
package main
import "github.com/dutchdata/goprivateproxy"
func main() {
config := GetConfig()
server := NewServer(config)
server.Start()
}
Build the binary
go build
Run to test your configuration
./goprivateproxy -config config.yaml
Set up as a systemd service
/etc/systemd/system/goprivateproxy.service
[Unit]
Description=Go Proxy Service
[Service]
ExecStart=/home/ec2-user/goprivateproxy/goprivateproxy -config /home/ec2-user/goprivateproxy/config.yaml
Restart=always
User=ec2-user
Group=ec2-user
WorkingDirectory=/home/ec2-user/goprivateproxy/
[Install]
WantedBy=multi-user.target
Start the service
sudo systemctl daemon-reload
sudo systemctl enable goprivateproxy
sudo systemctl start goprivateproxy
Check logs
journalctl -u goprivateproxy.service -f
License
This project is licensed under the MIT License - see the LICENSE file for details.