HTTP Proxy Setup¶
This guide covers how to configure and use HTTP proxies with Relyr for various networking scenarios.
Overview¶
HTTP proxies act as intermediaries between your client applications and target servers. Relyr provides comprehensive proxy support with features like:
- HTTP/HTTPS proxy support
- SOCKS4/SOCKS5 proxy support
- Authentication mechanisms
- Proxy rotation and load balancing
- SSL/TLS termination
Basic HTTP Proxy Configuration¶
Environment Variables¶
The simplest way to configure proxy settings is through environment variables:
# HTTP proxy
export HTTP_PROXY=http://proxy.example.com:8080
# HTTPS proxy
export HTTPS_PROXY=https://proxy.example.com:8080
# No proxy for specific domains
export NO_PROXY=localhost,127.0.0.1,.example.com
Configuration File¶
Create a relyr.yml configuration file:
proxy:
http:
host: proxy.example.com
port: 8080
protocol: http
https:
host: proxy.example.com
port: 8080
protocol: https
no_proxy:
- localhost
- 127.0.0.1
- "*.example.com"
Authentication¶
Basic Authentication¶
For proxies requiring username/password authentication:
proxy:
http:
host: proxy.example.com
port: 8080
auth:
type: basic
username: your_username
password: your_password
Or via environment variables:
Token-based Authentication¶
For modern authentication systems:
SOCKS Proxy Support¶
SOCKS5 Configuration¶
proxy:
socks:
host: socks.example.com
port: 1080
version: 5
auth:
username: your_username
password: your_password
SOCKS4 Configuration¶
Advanced Proxy Features¶
Proxy Rotation¶
Configure multiple proxies for load balancing and failover:
proxy:
rotation:
enabled: true
strategy: round_robin # round_robin, random, failover
proxies:
- host: proxy1.example.com
port: 8080
- host: proxy2.example.com
port: 8080
- host: proxy3.example.com
port: 8080
Health Checks¶
Monitor proxy health and automatically failover:
proxy:
health_check:
enabled: true
interval: 30s
timeout: 5s
url: http://httpbin.org/ip
expected_status: 200
SSL/TLS Configuration¶
For HTTPS proxies with custom certificates:
proxy:
https:
host: proxy.example.com
port: 8080
tls:
verify_cert: true
ca_cert_path: /path/to/ca.pem
client_cert_path: /path/to/client.pem
client_key_path: /path/to/client-key.pem
Proxy Chains¶
Chain multiple proxies for enhanced privacy:
proxy:
chain:
enabled: true
proxies:
- host: proxy1.example.com
port: 8080
type: http
- host: proxy2.example.com
port: 1080
type: socks5
Testing Proxy Configuration¶
Command Line Testing¶
Test your proxy configuration:
# Test HTTP proxy
relyr test-proxy --type http --host proxy.example.com --port 8080
# Test with authentication
relyr test-proxy --type http --host proxy.example.com --port 8080 \
--username user --password pass
# Test SOCKS proxy
relyr test-proxy --type socks5 --host socks.example.com --port 1080
Programmatic Testing¶
from relyr import ProxyClient
# Test proxy connectivity
client = ProxyClient(
proxy_host="proxy.example.com",
proxy_port=8080,
proxy_type="http"
)
result = client.test_connection()
if result.success:
print(f"Proxy working! IP: {result.external_ip}")
else:
print(f"Proxy failed: {result.error}")
Common Proxy Issues¶
Connection Timeouts¶
If experiencing timeouts, adjust timeout settings:
DNS Resolution¶
Configure DNS resolution through proxy:
IPv6 Support¶
Enable IPv6 proxy support:
Performance Optimization¶
Connection Pooling¶
Optimize performance with connection pooling:
Compression¶
Enable compression for better performance:
Security Considerations¶
Security Best Practices
- Never log proxy credentials in plain text
- Use encrypted connections (HTTPS/SOCKS5) when possible
- Regularly rotate proxy credentials
- Monitor proxy usage for suspicious activity
Credential Management¶
Store credentials securely:
Monitoring and Logging¶
Proxy Metrics¶
Monitor proxy performance:
monitoring:
proxy_metrics:
enabled: true
endpoint: /metrics
include:
- connection_count
- response_time
- error_rate
- throughput
Logging Configuration¶
Configure proxy-related logging:
Examples¶
See the Examples section for complete implementation examples and use cases.