mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
[优化] 增加中继 Vhost HTTP 端口支持并优化相关逻辑
This commit is contained in:
@@ -568,17 +568,18 @@ func buildSnapshotRoutes(routes []*model.ProxyRoute) ([]snapshotRoute, error) {
|
||||
}
|
||||
|
||||
func resolveTunnelOpenRestyUpstreamURL() string {
|
||||
port := 8080
|
||||
relayNodes, err := model.ListNodesByType("tunnel_relay")
|
||||
if err == nil {
|
||||
if err == nil && len(relayNodes) > 0 {
|
||||
for _, node := range relayNodes {
|
||||
if node != nil && node.RelayVhostHTTPPort > 0 {
|
||||
port = node.RelayVhostHTTPPort
|
||||
break
|
||||
if node != nil {
|
||||
addr := relayAgentAddress(node)
|
||||
if addr != "" {
|
||||
return "http://" + addr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("http://127.0.0.1:%d", port)
|
||||
return "http://127.0.0.1:8080"
|
||||
}
|
||||
|
||||
func buildSnapshotWAFDocument(routes []*model.ProxyRoute) (snapshotWAFDocument, error) {
|
||||
|
||||
@@ -436,6 +436,33 @@ func relayClientAddress(node *model.Node) string {
|
||||
return fmt.Sprintf("%s:%d", addr, port)
|
||||
}
|
||||
|
||||
func relayAgentAddress(node *model.Node) string {
|
||||
if node == nil {
|
||||
return ""
|
||||
}
|
||||
port := node.RelayVhostHTTPPort
|
||||
if port <= 0 {
|
||||
port = 8080
|
||||
}
|
||||
addr := strings.TrimSpace(node.RelayAgentAccessAddr)
|
||||
if addr == "" {
|
||||
addr = strings.TrimSpace(node.RelayClientAccessAddr)
|
||||
}
|
||||
if addr == "" {
|
||||
addr = strings.TrimSpace(node.IP)
|
||||
}
|
||||
if addr == "" {
|
||||
return fmt.Sprintf("127.0.0.1:%d", port)
|
||||
}
|
||||
if _, _, err := net.SplitHostPort(addr); err == nil {
|
||||
return addr
|
||||
}
|
||||
if strings.Contains(addr, ":") && strings.Count(addr, ":") > 1 {
|
||||
return net.JoinHostPort(addr, strconv.Itoa(port))
|
||||
}
|
||||
return fmt.Sprintf("%s:%d", addr, port)
|
||||
}
|
||||
|
||||
func parseTunnelTargetAddr(addr string) (string, int) {
|
||||
addr = strings.TrimSpace(addr)
|
||||
if addr == "" {
|
||||
|
||||
@@ -348,7 +348,7 @@ func TestTunnelRoutePublishAndFlaredConfigUseRelayPorts(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("PublishConfigVersion failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(result.Version.RenderedConfig, "server 127.0.0.1:18080 max_fails=3 fail_timeout=10s;") {
|
||||
if !strings.Contains(result.Version.RenderedConfig, "server de-e:18080 max_fails=3 fail_timeout=10s;") {
|
||||
t.Fatalf("expected rendered OpenResty upstream to use relay vhost port, got:\n%s", result.Version.RenderedConfig)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ const nodeEditorSchema = z
|
||||
ip_manual_override: z.boolean(),
|
||||
auto_update_enabled: z.boolean(),
|
||||
relay_bind_port: z.string().trim(),
|
||||
relay_vhost_http_port: z.string().trim(),
|
||||
relay_client_access_addr: z.string().trim(),
|
||||
relay_agent_access_addr: z.string().trim(),
|
||||
relay_client_proxy_url: z.string().trim(),
|
||||
@@ -74,6 +75,14 @@ const nodeEditorSchema = z
|
||||
message: '请填写正确的端口号 (1-65535)',
|
||||
});
|
||||
}
|
||||
const vhostPort = Number(values.relay_vhost_http_port);
|
||||
if (Number.isNaN(vhostPort) || vhostPort < 1 || vhostPort > 65535) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ['relay_vhost_http_port'],
|
||||
message: '请填写正确的端口号 (1-65535)',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!values.geo_manual_override) {
|
||||
@@ -129,6 +138,7 @@ const defaultValues: NodeEditorValues = {
|
||||
ip_manual_override: false,
|
||||
auto_update_enabled: false,
|
||||
relay_bind_port: '7000',
|
||||
relay_vhost_http_port: '8080',
|
||||
relay_client_access_addr: '',
|
||||
relay_agent_access_addr: '',
|
||||
relay_client_proxy_url: '',
|
||||
@@ -219,6 +229,7 @@ function buildFormValues(node?: Partial<NodeItem> | null): NodeEditorValues {
|
||||
ip_manual_override: node.ip_manual_override ?? false,
|
||||
auto_update_enabled: node.auto_update_enabled ?? false,
|
||||
relay_bind_port: String(node.relay_bind_port ?? 7000),
|
||||
relay_vhost_http_port: String(node.relay_vhost_http_port ?? 8080),
|
||||
relay_client_access_addr: node.relay_client_access_addr ?? '',
|
||||
relay_agent_access_addr: node.relay_agent_access_addr ?? '',
|
||||
relay_client_proxy_url: node.relay_client_proxy_url ?? '',
|
||||
@@ -244,6 +255,7 @@ function toPayload(values: NodeEditorValues): NodeMutationPayload {
|
||||
ip_manual_override: values.ip_manual_override,
|
||||
auto_update_enabled: values.auto_update_enabled,
|
||||
relay_bind_port: values.type === 'tunnel_relay' ? Number(values.relay_bind_port) : undefined,
|
||||
relay_vhost_http_port: values.type === 'tunnel_relay' ? Number(values.relay_vhost_http_port) : undefined,
|
||||
relay_client_access_addr: values.type === 'tunnel_relay' ? values.relay_client_access_addr.trim() : undefined,
|
||||
relay_agent_access_addr: values.type === 'tunnel_relay' ? values.relay_agent_access_addr.trim() : undefined,
|
||||
relay_client_proxy_url: values.type === 'tunnel_relay' ? values.relay_client_proxy_url.trim() : undefined,
|
||||
@@ -383,6 +395,14 @@ export function NodeEditorModal({
|
||||
<ResourceInput placeholder="7000" {...form.register('relay_bind_port')} />
|
||||
</ResourceField>
|
||||
|
||||
<ResourceField
|
||||
label="中继 Vhost HTTP 端口 (Vhost HTTP Port)"
|
||||
hint="中继服务端在此端口监听 HTTP 虚拟主机流量,用于 Nginx 转发到中继。"
|
||||
error={form.formState.errors.relay_vhost_http_port?.message}
|
||||
>
|
||||
<ResourceInput placeholder="8080" {...form.register('relay_vhost_http_port')} />
|
||||
</ResourceField>
|
||||
|
||||
<ResourceField
|
||||
label="客户端接入地址 (Client Access Addr)"
|
||||
hint="可选,如果不填默认使用节点的 IP + 绑定端口。"
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface NodeItem {
|
||||
ip: string;
|
||||
ip_manual_override: boolean;
|
||||
relay_bind_port: number;
|
||||
relay_vhost_http_port: number;
|
||||
relay_client_access_addr: string;
|
||||
relay_agent_access_addr: string;
|
||||
relay_client_proxy_url: string;
|
||||
@@ -54,6 +55,7 @@ export interface NodeMutationPayload {
|
||||
ip: string;
|
||||
ip_manual_override: boolean;
|
||||
relay_bind_port?: number;
|
||||
relay_vhost_http_port?: number;
|
||||
relay_client_access_addr?: string;
|
||||
relay_agent_access_addr?: string;
|
||||
relay_client_proxy_url?: string;
|
||||
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
getManagedDomains,
|
||||
} from '@/features/managed-domains/api/managed-domains';
|
||||
import { getProxyRoutes } from '@/features/proxy-routes/api/proxy-routes';
|
||||
import { getUpstreamSummary } from '@/features/proxy-routes/helpers';
|
||||
|
||||
import {
|
||||
deleteTlsCertificate,
|
||||
getTlsCertificates,
|
||||
@@ -539,7 +541,7 @@ export function WebsiteDetailPage({ websiteId }: { websiteId: string }) {
|
||||
</td>
|
||||
<td className="px-3 py-4 text-[var(--foreground-secondary)]">
|
||||
<div className="max-w-72 space-y-1 break-all">
|
||||
<p>{route.origin_url}</p>
|
||||
<p>{getUpstreamSummary(route)}</p>
|
||||
<p className="text-xs text-[var(--foreground-muted)]">
|
||||
回源主机名: {route.origin_host || '$host'}
|
||||
</p>
|
||||
|
||||
@@ -12,6 +12,7 @@ function buildNode(overrides: Partial<NodeItem> = {}): NodeItem {
|
||||
ip: '127.0.0.1',
|
||||
ip_manual_override: false,
|
||||
relay_bind_port: 7000,
|
||||
relay_vhost_http_port: 8080,
|
||||
relay_client_access_addr: '',
|
||||
relay_agent_access_addr: '',
|
||||
relay_client_proxy_url: '',
|
||||
|
||||
Reference in New Issue
Block a user