From b10fcf34c79302b8ee4936df0baee1dfb3782d07 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Sun, 7 Sep 2025 10:55:11 +0800 Subject: [PATCH 1/7] feat: Enhance caching options for proxy configuration --- agent/app/service/website.go | 9 +- agent/utils/nginx/components/location.go | 75 ++++++++-- frontend/src/api/interface/website.ts | 1 + frontend/src/lang/modules/en.ts | 3 +- frontend/src/lang/modules/es-es.ts | 1 + frontend/src/lang/modules/ja.ts | 1 + frontend/src/lang/modules/ko.ts | 1 + frontend/src/lang/modules/ms.ts | 1 + frontend/src/lang/modules/pt-br.ts | 1 + frontend/src/lang/modules/ru.ts | 1 + frontend/src/lang/modules/tr.ts | 1 + frontend/src/lang/modules/zh-Hant.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../config/basic/proxy/create/index.vue | 140 ++++++++++++------ 14 files changed, 177 insertions(+), 60 deletions(-) diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 9c0ea8eb4fa3..71d598c9af12 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1731,9 +1731,14 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) if err = openProxyCache(website); err != nil { return } - location.AddCache(req.CacheTime, req.CacheUnit, fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias), req.ServerCacheTime, req.ServerCacheUnit) + location.AddServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias), req.ServerCacheTime, req.ServerCacheUnit) } else { - location.RemoveCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias)) + location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias)) + } + if req.CacheTime != 0 { + location.AddBroswerCache(req.CacheTime, req.CacheUnit) + } else { + location.RemoveBroswerCache() } if len(req.Replaces) > 0 { location.AddSubFilter(req.Replaces) diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index b89e6c9bd3e0..e8505a74fa4d 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -253,10 +253,9 @@ func (l *Location) ChangePath(Modifier string, Match string) { l.Match = Match } -func (l *Location) AddCache(cacheTime int, cacheUint, cacheKey string, serverCacheTime int, serverCacheUint string) { +func (l *Location) AddBroswerCache(cacheTime int, cacheUint string) { l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) - l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) - l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) + l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) directives := l.GetDirectives() newDir := &Directive{ Name: "if", @@ -271,30 +270,80 @@ func (l *Location) AddCache(cacheTime int, cacheUint, cacheKey string, serverCac newDir.Block = block directives = append(directives, newDir) l.Directives = directives + l.CacheTime = cacheTime + l.CacheUint = cacheUint +} + +func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCacheUint string) { l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"}) l.UpdateDirective("proxy_cache", []string{cacheKey}) l.UpdateDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) l.UpdateDirective("proxy_cache_valid", []string{"200", "304", "301", "302", strconv.Itoa(serverCacheTime) + serverCacheUint}) l.Cache = true - l.CacheTime = cacheTime - l.CacheUint = cacheUint + l.ServerCacheTime = serverCacheTime + l.ServerCacheUint = serverCacheUint } -func (l *Location) RemoveCache(cacheKey string) { - l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) - l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) - l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie"}) - l.RemoveDirective("proxy_cache", []string{cacheKey}) - l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) - l.RemoveDirective("proxy_cache_valid", []string{"200"}) +// func (l *Location) AddCache(cacheKey string, serverCacheTime int, serverCacheUint string) { +// l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) +// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) +// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) +// directives := l.GetDirectives() +// newDir := &Directive{ +// Name: "if", +// Parameters: []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}, +// Block: &Block{}, +// } +// block := &Block{} +// block.Directives = append(block.Directives, &Directive{ +// Name: "expires", +// Parameters: []string{strconv.Itoa(cacheTime) + cacheUint}, +// }) +// newDir.Block = block +// directives = append(directives, newDir) +// l.Directives = directives +// l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"}) +// l.UpdateDirective("proxy_cache", []string{cacheKey}) +// l.UpdateDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) +// l.UpdateDirective("proxy_cache_valid", []string{"200", "304", "301", "302", strconv.Itoa(serverCacheTime) + serverCacheUint}) +// l.Cache = true +// l.CacheTime = cacheTime +// l.CacheUint = cacheUint +// } +func (l *Location) RemoveBroswerCache() { + l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) + l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) - l.CacheTime = 0 l.CacheUint = "" +} + +func (l *Location) RemoveServerCache(cacheKey string) { + l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"}) + l.RemoveDirective("proxy_cache", []string{cacheKey}) + l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) + l.RemoveDirective("proxy_cache_valid", []string{"200"}) l.Cache = false + l.ServerCacheTime = 0 + l.ServerCacheUint = "" } +// func (l *Location) RemoveCache(cacheKey string) { +// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) +// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) +// l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie"}) +// l.RemoveDirective("proxy_cache", []string{cacheKey}) +// l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) +// l.RemoveDirective("proxy_cache_valid", []string{"200"}) + +// l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) + +// l.CacheTime = 0 +// l.CacheUint = "" +// l.Cache = false +// } + func (l *Location) AddSubFilter(subFilters map[string]string) { l.RemoveDirective("sub_filter", []string{}) l.Replaces = subFilters diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 24edc664510c..576e2ffce76b 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -413,6 +413,7 @@ export namespace Website { allowHeaders: string; allowCredentials: boolean; preflight: boolean; + browserCache?: boolean; } export interface ProxReplace { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 40f14aa48f45..4e13f7a37b53 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2494,7 +2494,8 @@ const message = { 'The password is asymmetrically encrypted and cannot be echoed. Editing needs to reset the password', antiLeech: 'Anti-leech', extends: 'Extension', - browserCache: 'Cache', + browserCache: 'Browser Cache', + serverCache: 'Server Cache', leechLog: 'Record anti-leech log', accessDomain: 'Allowed domains', leechReturn: 'Response resource', diff --git a/frontend/src/lang/modules/es-es.ts b/frontend/src/lang/modules/es-es.ts index 17919abd1365..e86b461b62d5 100644 --- a/frontend/src/lang/modules/es-es.ts +++ b/frontend/src/lang/modules/es-es.ts @@ -2481,6 +2481,7 @@ const message = { antiLeech: 'Anti-hotlink', extends: 'Extensiones', browserCache: 'Caché de navegador', + serverCache: 'Caché del servidor', leechLog: 'Registrar logs anti-hotlink', accessDomain: 'Dominios permitidos', leechReturn: 'Recurso de respuesta', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 53e1c1be97d4..512d05a9ebe9 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -2408,6 +2408,7 @@ const message = { antiLeech: '反リーチ', extends: '拡大', browserCache: 'キャッシュ', + serverCache: 'サーバーキャッシュ', leechLog: '反リーチログを記録します', accessDomain: '許可されたドメイン', leechReturn: '応答リソース', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index 8207be58173f..2cc3c9157325 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -2365,6 +2365,7 @@ const message = { antiLeech: '링크 차단', extends: '확장', browserCache: '캐시', + serverCache: '서버 캐시', leechLog: '링크 차단 로그 기록', accessDomain: '허용된 도메인', leechReturn: '응답 리소스', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index d55e523895c4..35ddcb754d67 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -2465,6 +2465,7 @@ const message = { antiLeech: 'Anti-leech', extends: 'Pelanjutan', browserCache: 'Cache', + serverCache: 'Cache Pelayan', leechLog: 'Rekod log anti-leech', accessDomain: 'Domain yang dibenarkan', leechReturn: 'Sumber tindak balas', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index fa94a6230107..72e754590692 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -2468,6 +2468,7 @@ const message = { antiLeech: 'Anti-leech', extends: 'Extensão', browserCache: 'Cache', + serverCache: 'Cache do servidor', leechLog: 'Registrar log anti-leech', accessDomain: 'Domínios permitidos', leechReturn: 'Recurso de resposta', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index 6fc27aa0b38b..342fee3c9b61 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -2467,6 +2467,7 @@ const message = { antiLeech: 'Анти-лич', extends: 'Расширение', browserCache: 'Кэш', + serverCache: 'Кэш сервера', leechLog: 'Записывать лог анти-лича', accessDomain: 'Разрешенные домены', leechReturn: 'Ответ ресурса', diff --git a/frontend/src/lang/modules/tr.ts b/frontend/src/lang/modules/tr.ts index 761086ac84c5..510691fb69f0 100644 --- a/frontend/src/lang/modules/tr.ts +++ b/frontend/src/lang/modules/tr.ts @@ -2527,6 +2527,7 @@ const message = { antiLeech: 'Sömürü karşıtı', extends: 'Uzantı', browserCache: 'Önbellek', + serverCache: 'Sunucu önbelleği', leechLog: 'Sömürü karşıtı günlüğü kaydet', accessDomain: 'İzin verilen alan adları', leechReturn: 'Yanıt kaynağı', diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index de0ecf1edbfa..863912a063cd 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -2320,6 +2320,7 @@ const message = { antiLeech: '防盜鏈', extends: '副檔名', browserCache: '瀏覽器快取', + serverCache: '伺服器快取', leechLog: '記錄防盜鏈日誌', accessDomain: '允許的域名', leechReturn: '響應資源', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 93c295f51e67..34432e2239ec 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2313,6 +2313,7 @@ const message = { antiLeech: '防盗链', extends: '扩展名', browserCache: '浏览器缓存', + serverCache: '服务器缓存', leechLog: '记录防盗链日志', accessDomain: '允许的域名', leechReturn: '响应资源', diff --git a/frontend/src/views/website/website/config/basic/proxy/create/index.vue b/frontend/src/views/website/website/config/basic/proxy/create/index.vue index 7fc6088c8087..e3f45b751dae 100644 --- a/frontend/src/views/website/website/config/basic/proxy/create/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/create/index.vue @@ -74,51 +74,89 @@ {{ $t('website.cacheSettings') }} +
- {{ $t('website.enableCache') }} + {{ $t('website.serverCache') }}
- + + + {{ $t('commons.button.enable') }} + + + {{ $t('commons.button.disable') }} + +
-
- - - - - - - {{ $t('website.browserCacheTimeHelper') }} - - - - - - - - {{ $t('website.serverCacheTimeHelper') }} - - - +
+ + + + + {{ $t('website.serverCacheTimeHelper') }} + +
+ + + +
+
+ {{ $t('website.browserCache') }} +
+ + + {{ $t('commons.button.enable') }} + + + {{ $t('commons.button.disable') }} + + +
+ + +
+ + + + + {{ $t('website.browserCacheTimeHelper') }} +
@@ -234,6 +272,7 @@ const initData = (): Website.ProxyConfig => ({ proxySSLName: '', serverCacheTime: 10, serverCacheUnit: 'm', + browserCache: false, cors: false, allowOrigins: '*', allowMethods: 'GET,POST,OPTIONS,PUT,DELETE', @@ -255,6 +294,11 @@ const acceptParams = (proxyParam: Website.ProxyConfig) => { proxy.value = proxyParam; activeTab.value = 'basic'; + // Initialize browserCache based on cacheTime value + if (proxy.value.browserCache === undefined) { + proxy.value.browserCache = proxy.value.cacheTime > 0; + } + const res = getProtocolAndHost(proxyParam.proxyPass); if (res != null) { proxy.value.proxyProtocol = res.protocol; @@ -271,20 +315,28 @@ const acceptParams = (proxyParam: Website.ProxyConfig) => { } }; -const changeCache = (cache: boolean) => { +const changeServerCache = (cache: boolean) => { + proxy.value.cache = cache; if (cache) { - proxy.value.cacheTime = 1; - proxy.value.cacheUnit = 'm'; proxy.value.serverCacheTime = 10; proxy.value.serverCacheUnit = 'm'; } else { - proxy.value.cacheTime = 0; - proxy.value.cacheUnit = ''; proxy.value.serverCacheTime = 0; proxy.value.serverCacheUnit = ''; } }; +const changeBrowserCache = (cache: boolean) => { + proxy.value.browserCache = cache; + if (cache) { + proxy.value.cacheTime = 1; + proxy.value.cacheUnit = 'm'; + } else { + proxy.value.cacheTime = 0; + proxy.value.cacheUnit = ''; + } +}; + const addReplaces = () => { replaces.value.push({ key: '', value: '' }); }; From bc8b87cc03939191dd8ce605f81498b81869b1c5 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 12:08:37 +0800 Subject: [PATCH 2/7] fix: typo --- agent/app/service/website.go | 4 ++-- agent/utils/nginx/components/location.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 71d598c9af12..8eb624b83741 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1736,9 +1736,9 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias)) } if req.CacheTime != 0 { - location.AddBroswerCache(req.CacheTime, req.CacheUnit) + location.AddBrowserCache(req.CacheTime, req.CacheUnit) } else { - location.RemoveBroswerCache() + location.RemoveBrowserCache() } if len(req.Replaces) > 0 { location.AddSubFilter(req.Replaces) diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index e8505a74fa4d..afb192ab241d 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -253,7 +253,7 @@ func (l *Location) ChangePath(Modifier string, Match string) { l.Match = Match } -func (l *Location) AddBroswerCache(cacheTime int, cacheUint string) { +func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) { l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) directives := l.GetDirectives() @@ -311,7 +311,7 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa // l.CacheUint = cacheUint // } -func (l *Location) RemoveBroswerCache() { +func (l *Location) RemoveBrowserCache() { l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) From 29872d6d4a35e259bb9b91784d8d507af2a96b25 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 15:47:22 +0800 Subject: [PATCH 3/7] feat: Update caching and directive handling in proxy configuration --- agent/app/service/website.go | 5 +++++ agent/utils/nginx/components/location.go | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/agent/app/service/website.go b/agent/app/service/website.go index 8eb624b83741..b90398fd782b 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1727,6 +1727,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) location.UpdateDirective("proxy_pass", []string{req.ProxyPass}) location.UpdateDirective("proxy_set_header", []string{"Host", req.ProxyHost}) location.ChangePath(req.Modifier, req.Match) + // Server Cache Settings if req.Cache { if err = openProxyCache(website); err != nil { return @@ -1735,16 +1736,19 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) } else { location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias)) } + // Browser Cache Settings if req.CacheTime != 0 { location.AddBrowserCache(req.CacheTime, req.CacheUnit) } else { location.RemoveBrowserCache() } + // Content Replace Settings if len(req.Replaces) > 0 { location.AddSubFilter(req.Replaces) } else { location.RemoveSubFilter() } + // SSL Settings if req.SNI { location.UpdateDirective("proxy_ssl_server_name", []string{"on"}) if req.ProxySSLName != "" { @@ -1753,6 +1757,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) } else { location.UpdateDirective("proxy_ssl_server_name", []string{"off"}) } + // CORS Settings if req.Cors { location.UpdateDirective("add_header", []string{"Access-Control-Allow-Origin", req.AllowOrigins, "always"}) if req.AllowMethods != "" { diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index afb192ab241d..89156061108c 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -255,7 +255,8 @@ func (l *Location) ChangePath(Modifier string, Match string) { func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) { l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) - l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) + l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) + l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) directives := l.GetDirectives() newDir := &Directive{ Name: "if", @@ -286,8 +287,8 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa // func (l *Location) AddCache(cacheKey string, serverCacheTime int, serverCacheUint string) { // l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) -// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) -// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) +// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) +// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) // directives := l.GetDirectives() // newDir := &Directive{ // Name: "if", @@ -312,8 +313,8 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa // } func (l *Location) RemoveBrowserCache() { - l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) - l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) + l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) + l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) l.CacheTime = 0 l.CacheUint = "" @@ -330,8 +331,8 @@ func (l *Location) RemoveServerCache(cacheKey string) { } // func (l *Location) RemoveCache(cacheKey string) { -// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) -// l.RemoveDirective("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) +// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) +// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) // l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie"}) // l.RemoveDirective("proxy_cache", []string{cacheKey}) // l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) From e9745d671ef479a71b8de1add03acef4139b0f44 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 16:02:18 +0800 Subject: [PATCH 4/7] feat: Update default cache time and unit to improve caching configuration --- .../website/website/config/basic/proxy/create/index.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/website/website/config/basic/proxy/create/index.vue b/frontend/src/views/website/website/config/basic/proxy/create/index.vue index e3f45b751dae..8e93523b220d 100644 --- a/frontend/src/views/website/website/config/basic/proxy/create/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/create/index.vue @@ -257,8 +257,8 @@ const initData = (): Website.ProxyConfig => ({ operate: 'create', enable: true, cache: false, - cacheTime: 1, - cacheUnit: 'm', + cacheTime: 4, + cacheUnit: 'h', name: '', modifier: '', match: '/', @@ -329,8 +329,8 @@ const changeServerCache = (cache: boolean) => { const changeBrowserCache = (cache: boolean) => { proxy.value.browserCache = cache; if (cache) { - proxy.value.cacheTime = 1; - proxy.value.cacheUnit = 'm'; + proxy.value.cacheTime = 4; + proxy.value.cacheUnit = 'h'; } else { proxy.value.cacheTime = 0; proxy.value.cacheUnit = ''; From cf15f749438c1e204e61692fdd1929d87e43b9e2 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 16:10:07 +0800 Subject: [PATCH 5/7] feat: Implement RemoveCorsOption method to streamline CORS directive removal --- agent/app/service/website.go | 2 +- agent/utils/nginx/components/location.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/agent/app/service/website.go b/agent/app/service/website.go index b90398fd782b..7ed6cc1a3cdb 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1778,7 +1778,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) if req.Preflight { location.AddCorsOption() } else { - location.RemoveDirectiveByFullParams("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"}) + location.RemoveCorsOption() } } else { location.RemoveDirective("add_header", []string{"Access-Control-Allow-Origin"}) diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index 89156061108c..bbb4904a4a20 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -365,6 +365,7 @@ func (l *Location) RemoveSubFilter() { } func (l *Location) AddCorsOption() { + l.RemoveCorsOption() newDir := &Directive{ Name: "if", Parameters: []string{"(", "$request_method", "=", "'OPTIONS'", ")"}, @@ -392,3 +393,7 @@ func (l *Location) AddCorsOption() { directives = append(directives, newDir) l.Directives = directives } + +func (l *Location) RemoveCorsOption() { + l.RemoveDirectiveByFullParams("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"}) +} From 348f5a9a47ff9527b9e1ebb28078afa18e76839d Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 16:33:25 +0800 Subject: [PATCH 6/7] feat: Enhance cache display and initialization in proxy configuration --- .../website/config/basic/proxy/index.vue | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/frontend/src/views/website/website/config/basic/proxy/index.vue b/frontend/src/views/website/website/config/basic/proxy/index.vue index 18c3e5e13d66..e8fc69462b07 100644 --- a/frontend/src/views/website/website/config/basic/proxy/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/index.vue @@ -12,10 +12,17 @@ - + @@ -102,8 +109,8 @@ const initData = (id: number): Website.ProxyConfig => ({ operate: 'create', enable: true, cache: false, - cacheTime: 1, - cacheUnit: 'm', + cacheTime: 0, + cacheUnit: '', name: '', modifier: '', match: '/', @@ -113,6 +120,12 @@ const initData = (id: number): Website.ProxyConfig => ({ proxySSLName: '', serverCacheTime: 10, serverCacheUnit: 'm', + cors: false, + allowOrigins: '', + allowMethods: '', + allowHeaders: '', + allowCredentials: false, + preflight: false, }); const openCreate = () => { @@ -150,15 +163,6 @@ const deleteProxy = async (proxyConfig: Website.ProxyConfig) => { }); }; -const changeCache = (proxyConfig: Website.ProxyConfig) => { - proxyConfig.operate = 'edit'; - if (proxyConfig.cache) { - proxyConfig.cacheTime = 1; - proxyConfig.cacheUnit = 'm'; - } - submit(proxyConfig); -}; - const submit = async (proxyConfig: Website.ProxyConfig) => { loading.value = true; operateProxyConfig(proxyConfig) From 2176de2716b1727c88ce03c4fd0897f0cd53431e Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Fri, 24 Oct 2025 17:18:48 +0800 Subject: [PATCH 7/7] refactor: Clean up AddBrowserCache and RemoveCache methods by removing commented-out code --- agent/utils/nginx/components/location.go | 44 +----------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index bbb4904a4a20..ab81a543a703 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -256,7 +256,7 @@ func (l *Location) ChangePath(Modifier string, Match string) { func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) { l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) - l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) + l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) directives := l.GetDirectives() newDir := &Directive{ Name: "if", @@ -285,33 +285,6 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa l.ServerCacheUint = serverCacheUint } -// func (l *Location) AddCache(cacheKey string, serverCacheTime int, serverCacheUint string) { -// l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) -// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) -// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) -// directives := l.GetDirectives() -// newDir := &Directive{ -// Name: "if", -// Parameters: []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}, -// Block: &Block{}, -// } -// block := &Block{} -// block.Directives = append(block.Directives, &Directive{ -// Name: "expires", -// Parameters: []string{strconv.Itoa(cacheTime) + cacheUint}, -// }) -// newDir.Block = block -// directives = append(directives, newDir) -// l.Directives = directives -// l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"}) -// l.UpdateDirective("proxy_cache", []string{cacheKey}) -// l.UpdateDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) -// l.UpdateDirective("proxy_cache_valid", []string{"200", "304", "301", "302", strconv.Itoa(serverCacheTime) + serverCacheUint}) -// l.Cache = true -// l.CacheTime = cacheTime -// l.CacheUint = cacheUint -// } - func (l *Location) RemoveBrowserCache() { l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) @@ -330,21 +303,6 @@ func (l *Location) RemoveServerCache(cacheKey string) { l.ServerCacheUint = "" } -// func (l *Location) RemoveCache(cacheKey string) { -// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"}) -// l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"}) -// l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie"}) -// l.RemoveDirective("proxy_cache", []string{cacheKey}) -// l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"}) -// l.RemoveDirective("proxy_cache_valid", []string{"200"}) - -// l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) - -// l.CacheTime = 0 -// l.CacheUint = "" -// l.Cache = false -// } - func (l *Location) AddSubFilter(subFilters map[string]string) { l.RemoveDirective("sub_filter", []string{}) l.Replaces = subFilters