[反向代理]增加请求主机名类型选择

This commit is contained in:
GoEdgeLab
2020-11-30 22:27:55 +08:00
parent 2832767abc
commit 0c8e3e5c47
7 changed files with 57 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
) )
type SettingAction struct { type SettingAction struct {
@@ -62,6 +63,11 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
err = reverseProxyConfig.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
// 设置是否启用 // 设置是否启用
_, err = this.RPC().HTTPLocationRPC().UpdateHTTPLocationReverseProxy(this.AdminContext(), &pb.UpdateHTTPLocationReverseProxyRequest{ _, err = this.RPC().HTTPLocationRPC().UpdateHTTPLocationReverseProxy(this.AdminContext(), &pb.UpdateHTTPLocationReverseProxyRequest{
LocationId: params.LocationId, LocationId: params.LocationId,
@@ -75,6 +81,7 @@ func (this *SettingAction) RunPost(params struct {
// 设置反向代理相关信息 // 设置反向代理相关信息
_, 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),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
) )
type SettingAction struct { type SettingAction struct {
@@ -62,6 +63,11 @@ func (this *SettingAction) RunPost(params struct {
return return
} }
err = reverseProxyConfig.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
// 设置是否启用 // 设置是否启用
_, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{ _, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
ServerId: params.ServerId, ServerId: params.ServerId,
@@ -75,6 +81,7 @@ func (this *SettingAction) RunPost(params struct {
// 设置反向代理相关信息 // 设置反向代理相关信息
_, 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),
RequestHost: reverseProxyConfig.RequestHost, RequestHost: reverseProxyConfig.RequestHost,
RequestURI: reverseProxyConfig.RequestURI, RequestURI: reverseProxyConfig.RequestURI,
StripPrefix: reverseProxyConfig.StripPrefix, StripPrefix: reverseProxyConfig.StripPrefix,

View File

@@ -77,12 +77,12 @@ Vue.component("origin-list-table", {
</tr> </tr>
</thead> </thead>
<tr v-for="origin in vOrigins"> <tr v-for="origin in vOrigins">
<td>{{origin.addr}} <td :class="{disabled:!origin.isOn}">{{origin.addr}}
<div v-if="origin.name.length > 0" style="margin-top: 0.5em"> <div v-if="origin.name.length > 0" style="margin-top: 0.5em">
<tiny-basic-label>{{origin.name}}</tiny-basic-label> <tiny-basic-label>{{origin.name}}</tiny-basic-label>
</div> </div>
</td> </td>
<td>{{origin.weight}}</td> <td :class="{disabled:!origin.isOn}">{{origin.weight}}</td>
<td> <td>
<label-on :v-is-on="origin.isOn"></label-on> <label-on :v-is-on="origin.isOn"></label-on>
</td> </td>

View File

@@ -15,7 +15,9 @@ Vue.component("reverse-proxy-box", {
reverseProxyConfig = { reverseProxyConfig = {
requestPath: "", requestPath: "",
stripPrefix: "", stripPrefix: "",
requestURI: "" requestURI: "",
requestHost: "",
requestHostType: 0
} }
} }
return { return {
@@ -24,6 +26,15 @@ Vue.component("reverse-proxy-box", {
advancedVisible: false advancedVisible: false
} }
}, },
watch: {
"reverseProxyConfig.requestHostType": function (v) {
let requestHostType = parseInt(v)
if (isNaN(requestHostType)) {
requestHostType = 0
}
this.reverseProxyConfig.requestHostType = requestHostType
}
},
methods: { methods: {
isOn: function () { isOn: function () {
return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn
@@ -47,16 +58,24 @@ Vue.component("reverse-proxy-box", {
</div> </div>
</td> </td>
</tr> </tr>
</tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && advancedVisible">
<tr> <tr>
<td>请求主机名<em>Host</em></td> <td>请求主机名<em>Host</em></td>
<td> <td>
<radio :v-value="0" v-model="reverseProxyConfig.requestHostType">跟随代理服务</radio> &nbsp;
<radio :v-value="1" v-model="reverseProxyConfig.requestHostType">跟随源站</radio> &nbsp;
<radio :v-value="2" v-model="reverseProxyConfig.requestHostType">自定义</radio>
<div v-show="reverseProxyConfig.requestHostType == 2" style="margin-top: 0.8em">
<input type="text" placeholder="比如example.com" v-model="reverseProxyConfig.requestHost"/> <input type="text" placeholder="比如example.com" v-model="reverseProxyConfig.requestHost"/>
<p class="comment">请求后端服务器时的Host用于修改后端服务器接收到的域名默认和客户端请求的主机名一致通常不必填写支持请求变量。</p> </div>
<p class="comment">请求源站时的Host用于修改源站接收到的域名
<span v-if="reverseProxyConfig.requestHostType == 0">"跟随代理服务"是指源站接收到的域名和当前代理服务保持一致</span>
<span v-if="reverseProxyConfig.requestHostType == 1">"跟随源站"是指源站接收到的域名仍然是填写的源站地址中的信息,不随代理服务域名改变而改变</span>
<span v-if="reverseProxyConfig.requestHostType == 2">自定义Host内容中支持请求变量</span>。</p>
</td> </td>
</tr> </tr>
</tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && advancedVisible">
<tr> <tr>
<td>请求URI<em>RequestURI</em></td> <td>请求URI<em>RequestURI</em></td>
<td> <td>

View File

@@ -316,7 +316,7 @@ Vue.component("ssl-config-box", {
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tbody> <tbody>
<tr v-show="vProtocol == 'https'"> <tr v-show="vProtocol == 'https'">
<td class="title">用HTTP/2</td> <td class="title">用HTTP/2</td>
<td> <td>
<div class="ui checkbox"> <div class="ui checkbox">
<input type="checkbox" value="1" v-model="policy.http2Enabled"/> <input type="checkbox" value="1" v-model="policy.http2Enabled"/>

View File

@@ -52,7 +52,7 @@
<td>参数名</td> <td>参数名</td>
<td> <td>
<input type="text" name="stickyParam" v-model="stickyParam" maxlength="50"/> <input type="text" name="stickyParam" v-model="stickyParam" maxlength="50"/>
<p class="comment">记录或指定后端服务器的参数名只能是英文字母和数字的组合不允许有下划线因为在HTTP Header中下划线是不标准的</p> <p class="comment">记录或指定源站的参数名只能是英文字母和数字的组合不允许有下划线因为在HTTP Header中下划线是不标准的</p>
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -52,7 +52,7 @@
<td>参数名</td> <td>参数名</td>
<td> <td>
<input type="text" name="stickyParam" v-model="stickyParam" maxlength="50"/> <input type="text" name="stickyParam" v-model="stickyParam" maxlength="50"/>
<p class="comment">记录或指定后端服务器的参数名只能是英文字母和数字的组合不允许有下划线因为在HTTP Header中下划线是不标准的</p> <p class="comment">记录或指定源站的参数名只能是英文字母和数字的组合不允许有下划线因为在HTTP Header中下划线是不标准的</p>
</td> </td>
</tr> </tr>
</table> </table>