步骤 1:安装NaiveProxy
根据您的操作环境选择安装方法:
-
从源码安装(Linux/macOS):
- 克隆仓库:
git clone https://github.com/nayoo/NaiveProxy.git - 进入目录:
cd NaiveProxy - 编译:
make - 安装:
sudo make install
- 克隆仓库:
-
使用Docker安装:
- 拉取镜像:
docker pull nayoo/naiveproxy - 启动:
docker run -p 808:808 -p 8443:8443 nayoo/naiveproxy
- 拉取镜像:
步骤 2:生成SSL证书
确保域名已正确解析:
-
安装证书工具(如Let's Encrypt的Certbot):
- Linux/macOS:
sudo apt-get install certbot - Windows:使用Certbot的Windows版本或其他工具。
- Linux/macOS:
-
生成证书:
- 运行:
certbot certonly --server --name your_domain.com -d your_domain.com
- 运行:
-
检查 DNS 解析:
- 使用
nslookup your_domain.com或dig your_domain.com,确保指向正确的IP地址。
- 使用
步骤 3:配置NaiveProxy配置文件
创建配置文件config.json,按照以下结构填写:
{
"server": {
"listen": "...:808",
"ssl": {
"enable": true,
"cert_file": "/etc/letsencrypt/cert.pem",
"key_file": "/etc/letsencrypt/private.key.pem",
"ca_file": "/etc/letsencrypt/cacert.pem"
}
},
"domains": {
"your_domain.com": {
"backend": "http://192.168.1.100:808",
"proxy": {
"upstream": "http://192.168.1.101:80",
"reverse": {
"source": "127...1",
"uri": "/",
"prefix": "/reverse"
}
}
}
},
"routing": {
"rule": [
{
"domain": "localhost",
"to": "http://127...1:80"
},
{
"domain": "127...1",
"to": "http://127...1:80"
}
]
},
"load_balancing": {
"enabled": true,
"method": "round_robin",
"backends": [
"http://192.168.1.100:808",
"http://192.168.1.101:8081"
]
}
}
步骤 4:运行代理服务器
以命令运行NaiveProxy:
-
从源码运行:
./NaiveProxy -c config.json
-
使用Docker:
docker run -p 808:808 -p 8443:8443 --volume /etc/letsencrypt:/etc/letsencrypt nayoo/naiveproxy -c config.json
步骤 5:测试配置
使用curl或浏览器访问:
- 访问代理端口:
curl http://localhost:808 - 访问HTTPS端口:
curl https://localhost:8443
检查日志:
tail -f /var/log/naiveproxy.log
常见问题解决
- 证书错误:确保证书文件路径正确,权限设置为可读。
- 域名解析问题:检查DNS记录,确保域名指向正确的IP。
- 配置错误:检查JSON格式,确保所有引号和括号正确。
高级配置
- SSL优化:在
server.ssl中调整ssl_options,如启用TLS版本。 - 压缩支持:在
server.ciphers中添加zlib压缩。 - 缓存策略:在
server.cache中配置缓存时间和大小。
获取帮助
- 检查文档:NaiveProxy GitHub
- 社区支持:Discord或论坛
- 日志详细信息:查阅日志文件,解决配置问题。
通过以上步骤,您应该能够成功配置并运行NaiveProxy,满足反向代理和负载均衡的需求,遇到问题时,逐步排查配置和日志信息,确保每一步都正确无误。









