Vue.component("reverse-proxy-box", { props: ["v-reverse-proxy-ref", "v-reverse-proxy-config", "v-is-location", "v-is-group", "v-family"], data: function () { let reverseProxyRef = this.vReverseProxyRef if (reverseProxyRef == null) { reverseProxyRef = { isPrior: false, isOn: false, reverseProxyId: 0 } } let reverseProxyConfig = this.vReverseProxyConfig if (reverseProxyConfig == null) { reverseProxyConfig = { requestPath: "", stripPrefix: "", requestURI: "", requestHost: "", requestHostType: 0, addHeaders: [], connTimeout: {count: 0, unit: "second"}, readTimeout: {count: 0, unit: "second"}, idleTimeout: {count: 0, unit: "second"}, maxConns: 0, maxIdleConns: 0, followRedirects: false } } if (reverseProxyConfig.addHeaders == null) { reverseProxyConfig.addHeaders = [] } if (reverseProxyConfig.connTimeout == null) { reverseProxyConfig.connTimeout = {count: 0, unit: "second"} } if (reverseProxyConfig.readTimeout == null) { reverseProxyConfig.readTimeout = {count: 0, unit: "second"} } if (reverseProxyConfig.idleTimeout == null) { reverseProxyConfig.idleTimeout = {count: 0, unit: "second"} } if (reverseProxyConfig.proxyProtocol == null) { // 如果直接赋值Vue将不会触发变更通知 Vue.set(reverseProxyConfig, "proxyProtocol", { isOn: false, version: 1 }) } let forwardHeaders = [ { name: "X-Real-IP", isChecked: false }, { name: "X-Forwarded-For", isChecked: false }, { name: "X-Forwarded-By", isChecked: false }, { name: "X-Forwarded-Host", isChecked: false }, { name: "X-Forwarded-Proto", isChecked: false } ] forwardHeaders.forEach(function (v) { v.isChecked = reverseProxyConfig.addHeaders.$contains(v.name) }) return { reverseProxyRef: reverseProxyRef, reverseProxyConfig: reverseProxyConfig, advancedVisible: false, family: this.vFamily, forwardHeaders: forwardHeaders } }, watch: { "reverseProxyConfig.requestHostType": function (v) { let requestHostType = parseInt(v) if (isNaN(requestHostType)) { requestHostType = 0 } this.reverseProxyConfig.requestHostType = requestHostType }, "reverseProxyConfig.connTimeout.count": function (v) { let count = parseInt(v) if (isNaN(count) || count < 0) { count = 0 } this.reverseProxyConfig.connTimeout.count = count }, "reverseProxyConfig.readTimeout.count": function (v) { let count = parseInt(v) if (isNaN(count) || count < 0) { count = 0 } this.reverseProxyConfig.readTimeout.count = count }, "reverseProxyConfig.idleTimeout.count": function (v) { let count = parseInt(v) if (isNaN(count) || count < 0) { count = 0 } this.reverseProxyConfig.idleTimeout.count = count }, "reverseProxyConfig.maxConns": function (v) { let maxConns = parseInt(v) if (isNaN(maxConns) || maxConns < 0) { maxConns = 0 } this.reverseProxyConfig.maxConns = maxConns }, "reverseProxyConfig.maxIdleConns": function (v) { let maxIdleConns = parseInt(v) if (isNaN(maxIdleConns) || maxIdleConns < 0) { maxIdleConns = 0 } this.reverseProxyConfig.maxIdleConns = maxIdleConns }, "reverseProxyConfig.proxyProtocol.version": function (v) { let version = parseInt(v) if (isNaN(version)) { version = 1 } this.reverseProxyConfig.proxyProtocol.version = version } }, methods: { isOn: function () { if (this.vIsLocation || this.vIsGroup) { return this.reverseProxyRef.isPrior && this.reverseProxyRef.isOn } return this.reverseProxyRef.isOn }, changeAdvancedVisible: function (v) { this.advancedVisible = v }, changeAddHeader: function () { this.reverseProxyConfig.addHeaders = this.forwardHeaders.filter(function (v) { return v.isChecked }).map(function (v) { return v.name }) } }, template: `
| 启用反向代理 |
|
| 回源主机名(Host) |
请求源站时的Host,用于修改源站接收到的域名 ,"跟随代理服务"是指源站接收到的域名和当前代理服务保持一致 ,"跟随源站"是指源站接收到的域名仍然是填写的源站地址中的信息,不随代理服务域名改变而改变 ,自定义Host内容中支持请求变量。 |
| 回源跟随 |
选中后,自动读取源站跳转后的网页内容。 |
| 自动添加的Header |
选中后,会自动向源站请求添加这些Header。 |
| 请求URI(RequestURI) |
\${requestURI}为完整的请求URI,可以使用类似于"\${requestURI}?arg1=value1&arg2=value2"的形式添加你的参数。 |
| 去除URL前缀(StripPrefix) |
可以把请求的路径部分前缀去除后再查找文件,比如把 /web/app/index.html 去除前缀 /web 后就变成 /app/index.html。 |
| 是否自动刷新缓存区(AutoFlush) |
开启后将自动刷新缓冲区数据到客户端,在类似于SSE(server-sent events)等场景下很有用。 |
| 源站连接失败超时时间 |
秒
连接源站失败的最大超时时间,0表示不限制。 |
| 源站读取超时时间 |
秒
读取内容时的最大超时时间,0表示不限制。 |
| 源站最大并发连接数 |
源站可以接受到的最大并发连接数,0表示使用系统默认。 |
| 源站最大空闲连接数 |
当没有请求时,源站保持等待的最大空闲连接数量,0表示使用系统默认。 |
| 源站最大空闲超时时间 |
秒
源站保持等待的空闲超时时间,0表示使用默认时间。 |
| PROXY Protocol |
选中后表示启用PROXY Protocol,每次连接源站时都会在头部写入客户端地址信息。 |
| PROXY Protocol版本 |
发送类似于 发送二进制格式的头部信息。 |