Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代理配置优化 #653

Merged
merged 11 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions web/static/app/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -2186,19 +2186,19 @@ function pluginConfig(_name, version, func){
}

editor = CodeMirror.fromTextArea(document.getElementById("textBody"), {
lineNumbers: true,
matchBrackets:true,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Ctrl-F": "findPersistent",
"Ctrl-H": "replaceAll",
"Ctrl-S": function() {
saveDataFunc()
saveDataFunc();
},
"Cmd-S":function() {
saveDataFunc();
}
},
lineNumbers: true,
matchBrackets:true,
}
});
editor.focus();
$(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0});
Expand Down
49 changes: 31 additions & 18 deletions web/static/app/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,25 @@ function toProxy(siteName, type, obj) {
</div>\
</div>";
var editor;
function saveDataFunc(){
$("#configProxyBody").empty().text(editor.getValue());
var load = layer.load();
var data = {
siteName: siteName,
id: obj,
config: editor.getValue(),
};

$.post('/site/save_proxy_conf', data, function(res) {
layer.close(load)
if (res.status == true) {
layer.msg('保存成功', {icon: 1});
layer.close(index);
} else {
layer.msg(res.msg, {time: 3000,icon: 2});
}
},'json');
}
var index = layer.open({
type: 1,
title: '编辑配置文件',
Expand All @@ -1815,32 +1834,26 @@ function toProxy(siteName, type, obj) {
content: mBody,
success: function () {
editor = CodeMirror.fromTextArea(document.getElementById("configProxyBody"), {
extraKeys: {"Ctrl-Space": "autocomplete"},
lineNumbers: true,
matchBrackets:true,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Ctrl-F": "findPersistent",
"Ctrl-H": "replaceAll",
"Ctrl-S": function() {
saveDataFunc();
},
"Cmd-S":function() {
saveDataFunc();
}
}
});
editor.focus();
$(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0});
$("#onlineEditFileBtn").unbind('click');
},
yes:function(index,layero){
$("#configProxyBody").empty().text(editor.getValue());
var load = layer.load();
var data = {
siteName: siteName,
id: obj,
config: editor.getValue(),
};

$.post('/site/save_proxy_conf', data, function(res) {
layer.close(load)
if (res.status == true) {
layer.msg('保存成功', {icon: 1});
layer.close(index);
} else {
layer.msg(res.msg, {time: 3000,icon: 2});
}
},'json');
saveDataFunc();
return true;
},
});
Expand Down
86 changes: 45 additions & 41 deletions web/utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,53 +1513,57 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors,
if item["from"] == site_from:
return mw.returnData(False, "代理目录已存在!!")

tpl = "#PROXY-START\n \
location ^~ {from} {\n \
proxy_pass {to};\n \
proxy_set_header Host {host};\n \
proxy_ssl_server_name on;\n \
proxy_set_header X-Real-IP $remote_addr;\n \
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n \
proxy_set_header REMOTE-HOST $remote_addr;\n \
proxy_set_header Upgrade $http_upgrade;\n \
proxy_set_header Connection $connection_upgrade;\n \
proxy_http_version 1.1;\n \
\n \
add_header X-Cache $upstream_cache_status;\n \
{cors}\n \
\n \
{proxy_cache}\n \
tpl = "#PROXY-START\n\
location ^~ {from} {\n\
add_header X-Cache $upstream_cache_status;\n\
{cors}\n\
proxy_pass {to};\n\
proxy_set_header Host {host};\n\
proxy_ssl_server_name on;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header REMOTE-HOST $remote_addr;\n\
proxy_set_header Upgrade $http_upgrade;\n\
proxy_set_header Connection $connection_upgrade;\n\
proxy_http_version 1.1;\n\
\n\
{proxy_cache}\n\
}\n\
# PROXY-END"

tpl_proxy_cache = "\n \
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \
{\n \
expires {cache_time}m;\n \
}\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 \
tpl_proxy_cache = "\n\
if ( $uri ~* \\.(gif|png|jpg|jpeg|css|js|ttf|woff|woff2)$\" )\n\
{\n\
expires {cache_time}m;\n\
}\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\
"

tpl_proxy_nocache = "\n \
set $static_files_app 0; \n \
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \
{\n \
tpl_proxy_nocache_bak = "\n\
set $static_files_app 0; \n\
if ( $uri ~* \\.(gif|png|jpg|jpeg|css|js|ttf|woff|woff2)$\" )\n\
{\n\
set $static_files_app 1;\n\
expires 12h;\n\
}\n \
if ( $static_files_app = 0 )\n \
{\n \
add_header Cache-Control no-cache;\n \
}\n \
}\n\
if ( $static_files_app = 0 )\n\
{\n\
add_header Cache-Control no-cache;\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_nocache = "\n\
add_header Cache-Control no-cache;\n\
"
tpl_proxy_cors = "\n\
add_header Access-Control-Allow-Origin *;\n\
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\n\
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';\n\
if ($request_method = 'OPTIONS') {\n\
return 204;\n\
}\n\
"

# replace
Expand All @@ -1579,7 +1583,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors,
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)
Expand Down
Loading