geely-kaipiao/proxy/README.md
2026-05-24 21:08:10 +08:00

104 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 内网代理方案使用说明
## 问题描述
- **A设备当前设备**:可以监听端口,但无法访问内网网站
- **B设备局域网设备**:可以访问内网网站,但无法监听端口
## 解决方案
通过反向代理方式实现访问:
1. **A设备**运行代理服务器监听端口接收用户请求和B设备连接
2. **B设备**主动连接到A设备负责转发请求到内网网站
## 文件结构
```
proxy/
├── proxy_server.py # 运行在A设备上
├── proxy_client.py # 运行在B设备上
└── README.md # 使用说明
```
## 使用步骤
### 第一步在A设备当前设备上启动代理服务器
```bash
python proxy_server.py
```
输出示例:
```
A设备代理服务器已启动监听端口 8080
等待B设备连接和用户请求...
```
记录A设备的IP地址假设为 `192.168.1.50`
### 第二步在B设备上运行客户端程序
```bash
python proxy_client.py 192.168.1.50 8080
```
输出示例:
```
成功连接到A设备: 192.168.1.50:8080
准备转发请求到: superstar.geelytravel.com:443
```
### 第三步在A设备上访问内网网站
**方式一:设置浏览器代理**
1. 打开浏览器设置
2. 设置HTTP/HTTPS代理为`localhost:8080`
3. 访问:`https://superstar.geelytravel.com`
**方式二使用curl测试**
```bash
curl -x http://localhost:8080 https://superstar.geelytravel.com
```
## 工作原理
```
用户浏览器 → A设备(监听端口8080) → B设备 → 内网网站
↑ |
└────────────────────┘
响应返回路径
```
## 配置说明
### A设备proxy_server.py
```python
TARGET_HOST = 'superstar.geelytravel.com' # 目标内网网站
TARGET_PORT = 443 # HTTPS端口
LISTEN_PORT = 8080 # A设备监听端口
```
### B设备proxy_client.py
```python
TARGET_HOST = 'superstar.geelytravel.com' # 目标内网网站
TARGET_PORT = 443 # HTTPS端口
```
## 注意事项
1. 确保两台设备在同一局域网内
2. A设备的防火墙需要允许端口 `8080` 的入站连接
3. B设备需要能正常访问目标内网网站
4. 启动顺序先启动A设备的服务器再启动B设备的客户端
## 故障排除
**B设备无法连接到A设备**
- 检查A设备的IP地址是否正确
- 检查A设备的防火墙设置
- 确保A设备的代理服务器已启动
**网站无法访问:**
- 检查B设备是否能直接访问目标网站
- 检查网络连接是否正常
**连接不稳定:**
- 检查网络稳定性
- 考虑增加超时重试机制