支持PROXY Protocol

This commit is contained in:
GoEdgeLab
2021-10-12 20:18:29 +08:00
parent 66f781ab21
commit bddd053e47
5 changed files with 111 additions and 34 deletions

View File

@@ -87,15 +87,26 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
// PROXY Protocol
var proxyProtocolJSON = []byte{}
if reverseProxyConfig.ProxyProtocol != nil {
proxyProtocolJSON, err = json.Marshal(reverseProxyConfig.ProxyProtocol)
if err != nil {
this.ErrorPage(err)
return
}
}
// 设置反向代理相关信息 // 设置反向代理相关信息
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{ _, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
ReverseProxyId: reverseProxyConfig.Id, ReverseProxyId: reverseProxyConfig.Id,
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType), RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders, AddHeaders: reverseProxyConfig.AddHeaders,
ProxyProtocolJSON: proxyProtocolJSON,
}) })
this.Success() this.Success()

View File

@@ -87,15 +87,26 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
// PROXY Protocol
var proxyProtocolJSON = []byte{}
if reverseProxyConfig.ProxyProtocol != nil {
proxyProtocolJSON, err = json.Marshal(reverseProxyConfig.ProxyProtocol)
if err != nil {
this.ErrorPage(err)
return
}
}
// 设置反向代理相关信息 // 设置反向代理相关信息
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{ _, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
ReverseProxyId: reverseProxyConfig.Id, ReverseProxyId: reverseProxyConfig.Id,
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType), RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders, AddHeaders: reverseProxyConfig.AddHeaders,
ProxyProtocolJSON: proxyProtocolJSON,
}) })
this.Success() this.Success()

View File

@@ -78,15 +78,26 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
// PROXY Protocol
var proxyProtocolJSON = []byte{}
if reverseProxyConfig.ProxyProtocol != nil {
proxyProtocolJSON, err = json.Marshal(reverseProxyConfig.ProxyProtocol)
if err != nil {
this.ErrorPage(err)
return
}
}
// 设置反向代理相关信息 // 设置反向代理相关信息
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{ _, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
ReverseProxyId: reverseProxyConfig.Id, ReverseProxyId: reverseProxyConfig.Id,
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType), RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders, AddHeaders: reverseProxyConfig.AddHeaders,
ProxyProtocolJSON: proxyProtocolJSON,
}) })
this.Success() this.Success()

View File

@@ -106,20 +106,31 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
// PROXY Protocol
var proxyProtocolJSON = []byte{}
if reverseProxyConfig.ProxyProtocol != nil {
proxyProtocolJSON, err = json.Marshal(reverseProxyConfig.ProxyProtocol)
if err != nil {
this.ErrorPage(err)
return
}
}
// 设置反向代理相关信息 // 设置反向代理相关信息
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{ _, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
ReverseProxyId: reverseProxyConfig.Id, ReverseProxyId: reverseProxyConfig.Id,
RequestHostType: types.Int32(reverseProxyConfig.RequestHostType), RequestHostType: types.Int32(reverseProxyConfig.RequestHostType),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush, AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders, AddHeaders: reverseProxyConfig.AddHeaders,
ConnTimeoutJSON: connTimeoutJSON, ConnTimeoutJSON: connTimeoutJSON,
ReadTimeoutJSON: readTimeoutJSON, ReadTimeoutJSON: readTimeoutJSON,
IdleTimeoutJSON: idleTimeoutJSON, IdleTimeoutJSON: idleTimeoutJSON,
MaxConns: types.Int32(reverseProxyConfig.MaxConns), MaxConns: types.Int32(reverseProxyConfig.MaxConns),
MaxIdleConns: types.Int32(reverseProxyConfig.MaxIdleConns), MaxIdleConns: types.Int32(reverseProxyConfig.MaxIdleConns),
ProxyProtocolJSON: proxyProtocolJSON,
}) })
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)

View File

@@ -39,6 +39,14 @@ Vue.component("reverse-proxy-box", {
reverseProxyConfig.idleTimeout = {count: 0, unit: "second"} reverseProxyConfig.idleTimeout = {count: 0, unit: "second"}
} }
if (reverseProxyConfig.proxyProtocol == null) {
// 如果直接赋值Vue将不会触发变更通知
Vue.set(reverseProxyConfig, "proxyProtocol", {
isOn: false,
version: 1
})
}
let forwardHeaders = [ let forwardHeaders = [
{ {
name: "X-Real-IP", name: "X-Real-IP",
@@ -116,6 +124,13 @@ Vue.component("reverse-proxy-box", {
} }
this.reverseProxyConfig.maxIdleConns = maxIdleConns this.reverseProxyConfig.maxIdleConns = maxIdleConns
}, },
"reverseProxyConfig.proxyProtocol.version": function (v) {
let version = parseInt(v)
if (isNaN(version)) {
version = 1
}
this.reverseProxyConfig.proxyProtocol.version = version
}
}, },
methods: { methods: {
isOn: function () { isOn: function () {
@@ -194,7 +209,7 @@ Vue.component("reverse-proxy-box", {
<p class="comment">可以把请求的路径部分前缀去除后再查找文件,比如把 <span class="ui label tiny">/web/app/index.html</span> 去除前缀 <span class="ui label tiny">/web</span> 后就变成 <span class="ui label tiny">/app/index.html</span>。 </p> <p class="comment">可以把请求的路径部分前缀去除后再查找文件,比如把 <span class="ui label tiny">/web/app/index.html</span> 去除前缀 <span class="ui label tiny">/web</span> 后就变成 <span class="ui label tiny">/app/index.html</span>。 </p>
</td> </td>
</tr> </tr>
<tr> <tr v-if="family == null || family == 'http'">
<td>是否自动刷新缓存区<em>AutoFlush</em></td> <td>是否自动刷新缓存区<em>AutoFlush</em></td>
<td> <td>
<div class="ui checkbox"> <div class="ui checkbox">
@@ -268,6 +283,24 @@ Vue.component("reverse-proxy-box", {
<p class="comment">源站保持等待的空闲超时时间0表示使用默认时间。</p> <p class="comment">源站保持等待的空闲超时时间0表示使用默认时间。</p>
</td> </td>
</tr> </tr>
<tr v-show="family != 'unix'">
<td>PROXY Protocol</td>
<td>
<checkbox name="proxyProtocolIsOn" v-model="reverseProxyConfig.proxyProtocol.isOn"></checkbox>
<p class="comment">选中后表示启用PROXY Protocol每次连接源站时都会在头部写入客户端地址信息。</p>
</td>
</tr>
<tr v-show="family != 'unix' && reverseProxyConfig.proxyProtocol.isOn">
<td>PROXY Protocol版本</td>
<td>
<select class="ui dropdown auto-width" name="proxyProtocolVersion" v-model="reverseProxyConfig.proxyProtocol.version">
<option value="1">1</option>
<option value="2">2</option>
</select>
<p class="comment" v-if="reverseProxyConfig.proxyProtocol.version == 1">发送类似于<code-label>PROXY TCP4 192.168.1.1 192.168.1.10 32567 443</code-label>的头部信息。</p>
<p class="comment" v-if="reverseProxyConfig.proxyProtocol.version == 2">发送二进制格式的头部信息。</p>
</td>
</tr>
</tbody> </tbody>
</table> </table>
<div class="margin"></div> <div class="margin"></div>