From ea3033e22af9f532bb1677ebb61453e97c66217f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:07:29 +0800 Subject: [PATCH] Update site.py --- web/utils/site.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 97c531690..2f7261006 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1513,8 +1513,9 @@ class sites(object): if item["from"] == site_from: return mw.returnData(False, "代理目录已存在!!") - tpl = "#PROXY-START\n \ + tpl = "#PROXY-START\n\ location ^~ {from} {\n \ + {cors}\n\ proxy_pass {to};\n \ proxy_set_header Host {host};\n \ proxy_ssl_server_name on;\n \ @@ -1526,13 +1527,12 @@ location ^~ {from} {\n \ proxy_http_version 1.1;\n \ \n \ add_header X-Cache $upstream_cache_status;\n \ - {cors}\n \ \n \ {proxy_cache}\n \ }\n\ # PROXY-END" - tpl_proxy_cache = "\n \ + tpl_proxy_cache = "\n\ if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \ {\n \ expires {cache_time}m;\n \ @@ -1540,10 +1540,10 @@ location ^~ {from} {\n \ proxy_ignore_headers Set-Cookie Cache-Control expires;\n \ proxy_cache mw_cache;\n \ proxy_cache_key \"$host$uri$is_args$args\";\n \ - proxy_cache_valid 200 304 301 302 {cache_time}m;\n \ + proxy_cache_valid 200 304 301 302 {cache_time}m;\n\ " - tpl_proxy_nocache = "\n \ + tpl_proxy_nocache = "\n\ set $static_files_app 0; \n \ if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \ {\n \ @@ -1553,13 +1553,16 @@ location ^~ {from} {\n \ if ( $static_files_app = 0 )\n \ {\n \ add_header Cache-Control no-cache;\n \ - }\n \ + }\n\ " - tpl_proxy_cors = "\n \ - add_header 'Access-Control-Allow-Methods' 'GET,OPTIONS,POST' always;\n \ - add_header 'Access-Control-Allow-Credentials' 'true';\n \ - add_header 'Access-Control-Allow-Origin' *;\n \ - add_header 'Access-Control-Allow-Headers' *;\n \ + tpl_proxy_cors = "\n\ + add_header Access-Control-Allow-Origin *;\ + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\ + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';\ + add_header X-Cache $upstream_cache_status;\ + if ($request_method = 'OPTIONS') {\ + return 204;\ + }\ " # replace @@ -1579,7 +1582,7 @@ location ^~ {from} {\n \ if open_cors == 'on': tpl = tpl.replace("{cors}", tpl_proxy_cors, 999) else: - tpl = tpl.replace("{cors}", tpl_proxy_cors, 999) + tpl = tpl.replace("{cors}", '', 999) conf_proxy = "{}/{}.conf".format(self.getProxyPath(site_name), proxy_id)