Compare commits

..
3 Commits
Author SHA1 Message Date
刘河 848c44b130 自动替换跨站点url 2018-11-08 19:53:30 +08:00
刘河 079d3dedad 客户端错误处理机制修改 2018-11-06 16:43:06 +08:00
cnlh 9ebb7c3209 Update README.md 2018-11-06 14:28:10 +08:00
3 changed files with 28 additions and 16 deletions
+12 -16
View File
@@ -55,13 +55,6 @@ httpport | 代理的http端口(与nginx配合使用)
名称 | 含义
---|---
config | 配置文件路径
- 详细说明
[详细教程](https://github.com/cnlh/easyProxy/wiki/%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)
## 配置文件config.json
```
@@ -74,12 +67,12 @@ config | 配置文件路径
},
"SiteList": [
{
"host": "a.server.ourcauc.com",
"host": "server1.ourcauc.com",
"url": "10.1.50.203",
"port": 80
},
{
"host": "b.server.ourcauc.com",
"host": "server2.ourcauc.com",
"url": "10.1.50.196",
"port": 4000
}
@@ -118,11 +111,11 @@ upstream nodejs {
}
server {
listen 80;
server_name *.server.ourcauc.com;
server_name server1.ourcauc.com server2.ourcauc.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host:8224;
proxy_set_header Host $http_host:8024;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://nodejs;
@@ -130,11 +123,14 @@ server {
}
```
## 域名配置示例
> -server A 123.206.77.88
> *.server CNAME server.ourcauc.com.
> -server1 A 123.206.77.88
> -server2 A 123.206.77.88
## 操作系统支持
支持Windows、Linux、MacOSX等,无第三方依赖库。
支持Windows、Linux、MacOSX等,无第三方依赖库。
## 二级域名泛解析配置详细教程
[详细教程](https://github.com/cnlh/easyProxy/wiki/%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)
+6
View File
@@ -93,6 +93,7 @@ func (c *TRPClient) deal(conn net.Conn) error {
if nlen <= 0 {
log.Println("数据长度错误。")
c.werror(conn)
return errors.New("数据长度错误")
}
raw := make([]byte, nlen)
n, err := conn.Read(raw)
@@ -102,11 +103,13 @@ func (c *TRPClient) deal(conn net.Conn) error {
if n != int(nlen) {
log.Printf("读取服务端数据长度错误,已经读取%dbyte,总长度%d字节\n", n, nlen)
c.werror(conn)
return errors.New("读取服务端数据长度错误")
}
req, err := DecodeRequest(raw)
if err != nil {
log.Println("DecodeRequest错误:", err)
c.werror(conn)
return err
}
rawQuery := ""
if req.URL.RawQuery != "" {
@@ -122,6 +125,7 @@ func (c *TRPClient) deal(conn net.Conn) error {
if err != nil && !disRedirect {
log.Println("请求本地客户端错误:", err)
c.werror(conn)
return err
}
if !disRedirect {
defer resp.Body.Close()
@@ -133,10 +137,12 @@ func (c *TRPClient) deal(conn net.Conn) error {
if err != nil {
log.Println("EncodeResponse错误:", err)
c.werror(conn)
return err
}
n, err = conn.Write(respBytes)
if err != nil {
log.Println("发送数据错误,错误:", err)
return err
}
if n != len(respBytes) {
log.Printf("发送数据长度错误,已经发送:%dbyte,总字节长:%dbyte\n", n, len(respBytes))
+10
View File
@@ -69,6 +69,7 @@ func EncodeResponse(r *http.Response) ([]byte, error) {
raw := bytes.NewBuffer([]byte{})
binary.Write(raw, binary.LittleEndian, []byte("sign"))
respBytes, err := httputil.DumpResponse(r, true)
respBytes = replaceHost(respBytes)
if err != nil {
return nil, err
}
@@ -97,3 +98,12 @@ func getHost(str string) (string, error) {
}
return "", errors.New("没有找到解析的的host!")
}
func replaceHost(resp []byte) []byte {
str := string(resp)
for _, v := range config.SiteList {
str = strings.Replace(str, v.Url+":"+string(v.Port), v.Host, -1)
str = strings.Replace(str, v.Url, v.Host, -1)
}
return []byte(str)
}