diff --git a/agent/app/service/website.go b/agent/app/service/website.go index f7d1a6b2b56c..d86d81a07c0d 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -1759,10 +1759,12 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias)) } // Browser Cache Settings - if req.CacheTime != 0 { + if req.CacheTime > 0 { location.AddBrowserCache(req.CacheTime, req.CacheUnit) - } else { + } else if req.CacheTime == 0 { location.RemoveBrowserCache() + } else { + location.AddBroswerNoCache() } // Content Replace Settings if len(req.Replaces) > 0 { @@ -1945,10 +1947,8 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e } proxyConfig.ProxyPass = location.ProxyPass proxyConfig.Cache = location.Cache - if location.CacheTime > 0 { - proxyConfig.CacheTime = location.CacheTime - proxyConfig.CacheUnit = location.CacheUint - } + proxyConfig.CacheTime = location.CacheTime + proxyConfig.CacheUnit = location.CacheUint if location.ServerCacheTime > 0 { proxyConfig.ServerCacheTime = location.ServerCacheTime proxyConfig.ServerCacheUnit = location.ServerCacheUint diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index a915f8c94765..eb2740d247a7 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -73,6 +73,12 @@ func NewLocation(directive IDirective) *Location { location.CacheUint = unit location.CacheTime = cacheTime } + if di.GetName() == "add_header" && len(di.GetParameters()) >= 2 { + if di.GetParameters()[0] == "Cache-Control" && di.GetParameters()[1] == "no-cache" { + location.CacheTime = -1 + location.CacheUint = "" + } + } } } if params[0] == "(" && params[1] == "$request_method" && params[2] == `=` && params[3] == `'OPTIONS'` && params[4] == ")" { @@ -274,6 +280,28 @@ func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) { l.CacheUint = cacheUint } +func (l *Location) AddBroswerNoCache() { + 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: "add_header", + Parameters: []string{"Cache-Control", "no-cache"}, + }) + newDir.Block = block + directives = append(directives, newDir) + l.Directives = directives + l.CacheTime = -1 + l.CacheUint = "s" +} + 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}) @@ -287,7 +315,7 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa 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)$"`, ")"}) - l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"}) + l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"}) l.CacheTime = 0 l.CacheUint = "" } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f503960ebbb3..d50d029c01a0 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2531,6 +2531,7 @@ const message = { antiLeech: 'Anti-leech', extends: 'Extension', browserCache: 'Browser Cache', + noModify: 'No Modify', serverCache: 'Server Cache', leechLog: 'Record anti-leech log', accessDomain: 'Allowed domains', diff --git a/frontend/src/lang/modules/es-es.ts b/frontend/src/lang/modules/es-es.ts index cf20c1811fa4..3907a3213ab0 100644 --- a/frontend/src/lang/modules/es-es.ts +++ b/frontend/src/lang/modules/es-es.ts @@ -2523,6 +2523,7 @@ const message = { antiLeech: 'Anti-hotlink', extends: 'Extensiones', browserCache: 'Caché de navegador', + noModify: 'No Modificar', serverCache: 'Caché del servidor', leechLog: 'Registrar logs anti-hotlink', accessDomain: 'Dominios permitidos', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 9042e2f50fe5..0d78430fa895 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -2450,6 +2450,7 @@ const message = { antiLeech: '反リーチ', extends: '拡大', browserCache: 'キャッシュ', + noModify: '変更しない', serverCache: 'サーバーキャッシュ', leechLog: '反リーチログを記録します', accessDomain: '許可されたドメイン', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index 24520ccb21a9..f3e382ef0661 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -2407,6 +2407,7 @@ const message = { antiLeech: '링크 차단', extends: '확장', browserCache: '캐시', + noModify: '수정 안 함', serverCache: '서버 캐시', leechLog: '링크 차단 로그 기록', accessDomain: '허용된 도메인', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index 0536fce1a869..62b9bddb5529 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -2504,6 +2504,7 @@ const message = { antiLeech: 'Anti-leech', extends: 'Pelanjutan', browserCache: 'Cache', + noModify: 'Tidak Ubah', serverCache: 'Cache Pelayan', leechLog: 'Rekod log anti-leech', accessDomain: 'Domain yang dibenarkan', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index 93ceed1c2cc3..6d6732ef57ca 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -2507,6 +2507,7 @@ const message = { antiLeech: 'Anti-leech', extends: 'Extensão', browserCache: 'Cache', + noModify: 'Não Modificar', serverCache: 'Cache do servidor', leechLog: 'Registrar log anti-leech', accessDomain: 'Domínios permitidos', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index b5e0f4bffaac..f9e43b00d1b9 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -2504,6 +2504,7 @@ const message = { antiLeech: 'Анти-лич', extends: 'Расширение', browserCache: 'Кэш', + noModify: 'Не изменять', serverCache: 'Кэш сервера', leechLog: 'Записывать лог анти-лича', accessDomain: 'Разрешенные домены', diff --git a/frontend/src/lang/modules/tr.ts b/frontend/src/lang/modules/tr.ts index ac73eea84d9f..f7ed51219960 100644 --- a/frontend/src/lang/modules/tr.ts +++ b/frontend/src/lang/modules/tr.ts @@ -2563,6 +2563,7 @@ const message = { antiLeech: 'Sömürü karşıtı', extends: 'Uzantı', browserCache: 'Önbellek', + noModify: 'Değiştirme', serverCache: 'Sunucu önbelleği', leechLog: 'Sömürü karşıtı günlüğü kaydet', accessDomain: 'İzin verilen alan adları', diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index 59b990c82498..9d8585084b03 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -2354,6 +2354,7 @@ const message = { antiLeech: '防盜鏈', extends: '副檔名', browserCache: '瀏覽器快取', + noModify: '不修改', serverCache: '伺服器快取', leechLog: '記錄防盜鏈日誌', accessDomain: '允許的域名', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 9a99475b2bb8..774f29648adc 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2351,6 +2351,7 @@ const message = { antiLeech: '防盗链', extends: '扩展名', browserCache: '浏览器缓存', + noModify: '不修改', serverCache: '服务器缓存', leechLog: '记录防盗链日志', accessDomain: '允许的域名', 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 8e93523b220d..a3c3f2203c13 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 @@ -124,24 +124,31 @@ {{ $t('commons.button.enable') }} {{ $t('commons.button.disable') }} + + {{ $t('website.noModify') }} + -
+