XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Add comprehensive reverse proxy documentation and examples

Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>

501689f5
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
提交于

代码差异

5 个文件 +952 -0
Added Caddyfile.example +58 -0
@@ -0,0 +1,58 @@
1 # Caddyfile for GPT4Free Reverse Proxy
2 # Place this file in the same directory as docker-compose-proxy.yml
3
4 # Replace with your actual domain name
5 # For local testing, you can use localhost or your IP address
6 {
7 # Global options
8 email your-email@example.com
9 }
10
11 # Main site configuration
12 your-domain.com {
13 # Automatic HTTPS with Let's Encrypt
14
15 # Reverse proxy to GPT4Free backend
16 reverse_proxy gpt4free:8080 {
17 # Preserve client information
18 header_up X-Real-IP {remote_host}
19 header_up X-Forwarded-For {remote_host}
20 header_up X-Forwarded-Proto {scheme}
21
22 # Timeouts for long-running requests
23 transport http {
24 read_timeout 60s
25 write_timeout 60s
26 }
27 }
28
29 # Security headers
30 header {
31 Strict-Transport-Security "max-age=31536000; includeSubDomains"
32 X-Content-Type-Options "nosniff"
33 X-Frame-Options "SAMEORIGIN"
34 X-XSS-Protection "1; mode=block"
35 Referrer-Policy "strict-origin-when-cross-origin"
36 }
37
38 # Logging
39 log {
40 output file /data/logs/access.log
41 format console
42 }
43
44 # Optional: Rate limiting
45 # Uncomment to enable
46 # rate_limit {
47 # zone dynamic {
48 # key {remote_host}
49 # events 100
50 # window 1m
51 # }
52 # }
53 }
54
55 # For local development without a domain (comment out the above and use this instead)
56 # localhost {
57 # reverse_proxy gpt4free:8080
58 # }
Modified README.md +15 -0
@@ -50,6 +50,7 @@ Table of contents
50 50 - [Providers & models (overview)](#providers--models-overview)
51 51 - [Local inference & media](#local-inference--media)
52 52 - [Configuration & customization](#configuration--customization)
53 - [Production deployment & reverse proxy](#production-deployment--reverse-proxy)
53 54 - [Running on smartphone](#running-on-smartphone)
54 55 - [Interference API (OpenAI‑compatible)](#interference-api-openai-compatible)
55 56 - [Examples & common patterns](#examples--common-patterns)
@@ -365,6 +366,20 @@ Provider requirements may include:
365 366
366 367 ---
367 368
369 ## Production deployment & reverse proxy
370 For production environments, it's recommended to deploy GPT4Free behind a reverse proxy for SSL/TLS termination, security, and load balancing.
371
372 - **Reverse Proxy Guide**: [docs/reverse-proxy.md](docs/reverse-proxy.md)
373 - Includes configuration examples for:
374 - **Nginx** (with Let's Encrypt SSL)
375 - **Caddy** (automatic HTTPS)
376 - **Apache** (with WebSocket support)
377 - **Traefik** (Docker-native)
378 - Security features: rate limiting, IP whitelisting, authentication
379 - Production best practices and troubleshooting tips
380
381 ---
382
368 383 ## Running on smartphone
369 384 - The web GUI is responsive and can be accessed from a phone by visiting your host IP:8080 or via a tunnel. See [docs/guides/phone.md](https://github.com/gpt4free/g4f.dev/blob/main/docs/guides/phone.md).
370 385
Added docker-compose-proxy.yml +49 -0
@@ -0,0 +1,49 @@
1 # Docker Compose with Reverse Proxy Example
2 # This example shows how to deploy GPT4Free with a Caddy reverse proxy
3 # for production use with automatic HTTPS
4
5 version: '3.8'
6
7 services:
8 # GPT4Free service (backend only, not exposed directly)
9 gpt4free:
10 image: hlohaus789/g4f:latest
11 shm_size: 2gb
12 container_name: gpt4free-backend
13 restart: unless-stopped
14 volumes:
15 - ./har_and_cookies:/app/har_and_cookies
16 - ./generated_media:/app/generated_media
17 # Only expose to internal network, not to host
18 expose:
19 - "8080"
20 networks:
21 - gpt4free-network
22 environment:
23 - OLLAMA_HOST=host.docker.internal
24
25 # Caddy reverse proxy with automatic HTTPS
26 caddy:
27 image: caddy:2-alpine
28 container_name: gpt4free-proxy
29 restart: unless-stopped
30 ports:
31 - "80:80"
32 - "443:443"
33 - "443:443/udp" # HTTP/3
34 volumes:
35 - ./Caddyfile:/etc/caddy/Caddyfile
36 - caddy_data:/data
37 - caddy_config:/config
38 networks:
39 - gpt4free-network
40 depends_on:
41 - gpt4free
42
43 networks:
44 gpt4free-network:
45 driver: bridge
46
47 volumes:
48 caddy_data:
49 caddy_config:
Added docs/reverse-proxy-quickstart.md +208 -0
@@ -0,0 +1,208 @@
1 # Quick Start Guide: GPT4Free with Reverse Proxy
2
3 This guide helps you quickly deploy GPT4Free with a reverse proxy for production use.
4
5 ## Prerequisites
6
7 - Docker and Docker Compose installed
8 - A domain name (for HTTPS) or use localhost for testing
9 - Ports 80 and 443 available
10
11 ## Option 1: Quick Start with Caddy (Recommended)
12
13 Caddy provides automatic HTTPS with Let's Encrypt, making it the easiest option.
14
15 ### Step 1: Clone the repository
16
17 ```bash
18 git clone https://github.com/xtekky/gpt4free.git
19 cd gpt4free
20 ```
21
22 ### Step 2: Configure Caddyfile
23
24 ```bash
25 # Copy the example Caddyfile
26 cp Caddyfile.example Caddyfile
27
28 # Edit the Caddyfile and replace 'your-domain.com' with your actual domain
29 nano Caddyfile
30 ```
31
32 For local testing without a domain, use this simple Caddyfile:
33 ```caddy
34 localhost {
35 reverse_proxy gpt4free:8080
36 }
37 ```
38
39 ### Step 3: Start the services
40
41 ```bash
42 # Start GPT4Free with Caddy reverse proxy
43 docker-compose -f docker-compose-proxy.yml up -d
44 ```
45
46 ### Step 4: Access GPT4Free
47
48 - **With domain**: https://your-domain.com
49 - **Local testing**: http://localhost
50
51 That's it! Caddy will automatically obtain and renew SSL certificates.
52
53 ## Option 2: Manual Setup with Nginx
54
55 If you prefer Nginx, follow these steps:
56
57 ### Step 1: Start GPT4Free (internal only)
58
59 ```bash
60 # Create directories
61 mkdir -p har_and_cookies generated_media
62
63 # Run GPT4Free on internal network only
64 docker run -d \
65 --name gpt4free \
66 --restart unless-stopped \
67 -p 127.0.0.1:8080:8080 \
68 -v ${PWD}/har_and_cookies:/app/har_and_cookies \
69 -v ${PWD}/generated_media:/app/generated_media \
70 hlohaus789/g4f:latest
71 ```
72
73 ### Step 2: Configure Nginx
74
75 Create `/etc/nginx/sites-available/gpt4free`:
76
77 ```nginx
78 server {
79 listen 80;
80 server_name your-domain.com;
81
82 location / {
83 proxy_pass http://127.0.0.1:8080;
84 proxy_http_version 1.1;
85
86 # WebSocket support
87 proxy_set_header Upgrade $http_upgrade;
88 proxy_set_header Connection "upgrade";
89
90 # Headers
91 proxy_set_header Host $host;
92 proxy_set_header X-Real-IP $remote_addr;
93 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
94 proxy_set_header X-Forwarded-Proto $scheme;
95
96 # Timeouts
97 proxy_read_timeout 60s;
98 }
99 }
100 ```
101
102 ### Step 3: Enable site and get SSL
103
104 ```bash
105 # Enable site
106 sudo ln -s /etc/nginx/sites-available/gpt4free /etc/nginx/sites-enabled/
107
108 # Test configuration
109 sudo nginx -t
110
111 # Get SSL certificate (certbot will modify your nginx config)
112 sudo certbot --nginx -d your-domain.com
113
114 # Reload nginx
115 sudo systemctl reload nginx
116 ```
117
118 ## Verification
119
120 After setup, verify your deployment:
121
122 1. **Check service status**:
123 ```bash
124 # For Docker Compose
125 docker-compose -f docker-compose-proxy.yml ps
126
127 # For manual Docker
128 docker ps
129 ```
130
131 2. **Test the API**:
132 ```bash
133 # Local test
134 curl http://localhost/v1/models
135
136 # With domain
137 curl https://your-domain.com/v1/models
138 ```
139
140 3. **Access the GUI**:
141 - Navigate to `https://your-domain.com/chat/` (or `http://localhost/chat/` for local)
142
143 4. **Check logs**:
144 ```bash
145 # Docker Compose
146 docker-compose -f docker-compose-proxy.yml logs -f
147
148 # Manual Docker
149 docker logs -f gpt4free
150 ```
151
152 ## Common Issues
153
154 ### Port Already in Use
155
156 If ports 80 or 443 are already in use:
157
158 ```bash
159 # Check what's using the ports
160 sudo lsof -i :80
161 sudo lsof -i :443
162
163 # Stop the conflicting service or use different ports
164 ```
165
166 ### SSL Certificate Issues
167
168 For Caddy:
169 - Ensure your domain's DNS points to your server
170 - Caddy needs to be accessible from the internet on port 80 for Let's Encrypt validation
171 - Check Caddy logs: `docker-compose -f docker-compose-proxy.yml logs caddy`
172
173 For Certbot/Nginx:
174 - Run `sudo certbot renew --dry-run` to test renewal
175 - Check nginx error logs: `sudo tail -f /var/log/nginx/error.log`
176
177 ### WebSocket Connection Failed
178
179 Ensure your reverse proxy configuration includes WebSocket support:
180 - Nginx: `proxy_set_header Upgrade $http_upgrade;` and `proxy_set_header Connection "upgrade";`
181 - Caddy: This is automatic
182 - Apache: Enable `mod_proxy_wstunnel`
183
184 ### Timeout Errors
185
186 Increase timeout values in your reverse proxy configuration if you experience timeouts with long-running requests.
187
188 ## Security Best Practices
189
190 1. **Always use HTTPS in production**
191 2. **Set up rate limiting** to prevent abuse
192 3. **Use firewall rules** to restrict access if needed
193 4. **Keep software updated**: Regularly update Docker images and reverse proxy
194 5. **Monitor logs** for suspicious activity
195 6. **Use strong API keys** if authentication is enabled
196
197 ## Next Steps
198
199 - **Full documentation**: See [docs/reverse-proxy.md](docs/reverse-proxy.md) for detailed configuration options
200 - **Security hardening**: Add rate limiting, IP whitelisting, and authentication
201 - **Monitoring**: Set up monitoring and alerting for your deployment
202 - **Backups**: Regularly backup the `har_and_cookies` directory
203
204 ## Getting Help
205
206 - **Documentation**: https://g4f.dev/docs
207 - **Issues**: https://github.com/xtekky/gpt4free/issues
208 - **Community**: Discord and Telegram (links in main README)