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

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

View File

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

View File

@@ -77,12 +77,12 @@ Vue.component("origin-list-table", {
</tr>
</thead>
<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">
<tiny-basic-label>{{origin.name}}</tiny-basic-label>
</div>
</td>
<td>{{origin.weight}}</td>
<td :class="{disabled:!origin.isOn}">{{origin.weight}}</td>
<td>
<label-on :v-is-on="origin.isOn"></label-on>
</td>

View File

@@ -15,7 +15,9 @@ Vue.component("reverse-proxy-box", {
reverseProxyConfig = {
requestPath: "",
stripPrefix: "",
requestURI: ""
requestURI: "",
requestHost: "",
requestHostType: 0
}
}
return {
@@ -24,6 +26,15 @@ Vue.component("reverse-proxy-box", {
advancedVisible: false
}
},
watch: {
"reverseProxyConfig.requestHostType": function (v) {
let requestHostType = parseInt(v)
if (isNaN(requestHostType)) {
requestHostType = 0
}
this.reverseProxyConfig.requestHostType = requestHostType
}
},
methods: {
isOn: function () {
return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn
@@ -47,16 +58,24 @@ Vue.component("reverse-proxy-box", {
</div>
</td>
</tr>
</tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && advancedVisible">
<tr>
<td>请求主机名<em>Host</em></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"/>
<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>
</tr>
</tbody>
<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
<tbody v-show="isOn() && advancedVisible">
<tr>
<td>请求URI<em>RequestURI</em></td>
<td>

View File

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

View File

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

View File

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