1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 解决删除HTTPS时候没有清除配置的问题

This commit is contained in:
zhengkunwang223 2023-01-11 15:15:48 +08:00 committed by zhengkunwang223
parent 1fcc21839a
commit 0e6530f0cc
12 changed files with 33 additions and 54 deletions

View File

@ -126,7 +126,7 @@ func updateNginxConfig(scope string, params []dto.NginxParam, website *model.Web
return nginxCheckAndReload(config.OldContent, config.FilePath, nginxFull.Install.ContainerName) return nginxCheckAndReload(config.OldContent, config.FilePath, nginxFull.Install.ContainerName)
} }
func deleteNginxConfig(scope string, keys []string, website *model.Website) error { func deleteNginxConfig(scope string, params []dto.NginxParam, website *model.Website) error {
nginxFull, err := getNginxFull(website) nginxFull, err := getNginxFull(website)
if err != nil { if err != nil {
return err return err
@ -144,8 +144,8 @@ func deleteNginxConfig(scope string, keys []string, website *model.Website) erro
block = config.Config.Block block = config.Config.Block
} }
for _, key := range keys { for _, param := range params {
block.RemoveDirective(key, []string{}) block.RemoveDirective(param.Name, param.Params)
} }
if err := nginx.WriteConfig(config.Config, nginx.IndentedStyle); err != nil { if err := nginx.WriteConfig(config.Config, nginx.IndentedStyle); err != nil {

View File

@ -455,7 +455,13 @@ func (w WebsiteService) UpdateNginxConfigByScope(req request.NginxConfigUpdate)
return err return err
} }
if req.Operate == constant.ConfigDel { if req.Operate == constant.ConfigDel {
return deleteNginxConfig(constant.NginxScopeServer, keys, &website) var nginxParams []dto.NginxParam
for _, key := range keys {
nginxParams = append(nginxParams, dto.NginxParam{
Name: key,
})
}
return deleteNginxConfig(constant.NginxScopeServer, nginxParams, &website)
} }
params := getNginxParams(req.Params, keys) params := getNginxParams(req.Params, keys)
if req.Operate == constant.ConfigNew { if req.Operate == constant.ConfigNew {
@ -547,9 +553,12 @@ func (w WebsiteService) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteH
if err := deleteListenAndServerName(website, []int{443}, []string{}); err != nil { if err := deleteListenAndServerName(website, []int{443}, []string{}); err != nil {
return response.WebsiteHTTPS{}, err return response.WebsiteHTTPS{}, err
} }
keys := getKeysFromStaticFile(dto.SSL) nginxParams := getNginxParamsFromStaticFile(dto.SSL, nil)
keys = append(keys, "if") nginxParams = append(nginxParams, dto.NginxParam{
if err := deleteNginxConfig(constant.NginxScopeServer, keys, &website); err != nil { Name: "if",
Params: []string{"($scheme", "=", "http)"},
})
if err := deleteNginxConfig(constant.NginxScopeServer, nginxParams, &website); err != nil {
return response.WebsiteHTTPS{}, err return response.WebsiteHTTPS{}, err
} }
if err := websiteRepo.Save(ctx, &website); err != nil { if err := websiteRepo.Save(ctx, &website); err != nil {
@ -771,7 +780,12 @@ func (w WebsiteService) OpWebsiteLog(req request.WebsiteLogReq) (*response.Websi
key = "error_log" key = "error_log"
website.ErrorLog = false website.ErrorLog = false
} }
if err := deleteNginxConfig(constant.NginxScopeServer, []string{key}, &website); err != nil { var nginxParams []dto.NginxParam
nginxParams = append(nginxParams, dto.NginxParam{
Name: key,
})
if err := deleteNginxConfig(constant.NginxScopeServer, nginxParams, &website); err != nil {
return nil, err return nil, err
} }
if err := websiteRepo.Save(context.Background(), &website); err != nil { if err := websiteRepo.Save(context.Background(), &website); err != nil {

View File

@ -42,6 +42,8 @@ var repeatKeys = map[string]struct {
"limit_conn": {}, "limit_conn": {},
"limit_conn_zone": {}, "limit_conn_zone": {},
"set": {}, "set": {},
"if": {},
"proxy_set_header": {},
} }
func IsRepeatKey(key string) bool { func IsRepeatKey(key string) bool {

View File

@ -277,4 +277,5 @@ func (s *Server) AddHTTP2HTTPS() {
}) })
newDir.Block = block newDir.Block = block
s.UpdateDirectiveBySecondKey("if", "($scheme", newDir) s.UpdateDirectiveBySecondKey("if", "($scheme", newDir)
} }

View File

@ -1,3 +0,0 @@
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}

View File

@ -1,14 +0,0 @@
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
client_max_body_size 50m;
keepalive_timeout 60;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";

View File

@ -7,9 +7,6 @@ import (
//go:embed ssl.conf //go:embed ssl.conf
var SSL []byte var SSL []byte
//go:embed http2https.conf
var HTTPS []byte
//go:embed website_default.conf //go:embed website_default.conf
var WebsiteDefault []byte var WebsiteDefault []byte
@ -18,6 +15,3 @@ var Limit []byte
//go:embed index.html //go:embed index.html
var Index []byte var Index []byte
//go:embed http_per.conf
var HttpPer []byte

View File

@ -7,3 +7,4 @@ ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m; ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000"; add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri; error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;

View File

@ -1,8 +1,6 @@
<template> <template>
<el-tag :type="getType(status)" round effect="light"> <el-tag :type="getType(status)" round effect="light">
<!-- <span :style="{ color: getColor(status) }"> -->
{{ $t('commons.status.' + status) }} {{ $t('commons.status.' + status) }}
<!-- </span> -->
</el-tag> </el-tag>
</template> </template>
@ -17,17 +15,6 @@ const props = defineProps({
}); });
let status = ref('running'); let status = ref('running');
// const getColor = (status: string) => {
// switch (status) {
// case 'running':
// return '#00c957';
// case 'error':
// return '#ff0000';
// default:
// return '';
// }
// };
const getType = (status: string) => { const getType = (status: string) => {
switch (status) { switch (status) {
case 'running': case 'running':

View File

@ -3,9 +3,9 @@ import zh from './modules/zh';
import en from './modules/en'; import en from './modules/en';
const i18n = createI18n({ const i18n = createI18n({
legacy: false, // 如果要支持 compositionAPI此项必须设置为 false legacy: false,
locale: 'zh', // 设置语言类型 locale: 'zh',
globalInjection: true, // 全局注册$t方法 globalInjection: true,
messages: { messages: {
zh, zh,
en, en,

View File

@ -9,7 +9,7 @@ export const GlobalStore = defineStore({
state: (): GlobalState => ({ state: (): GlobalState => ({
isLogin: false, isLogin: false,
csrfToken: '', csrfToken: '',
assemblySize: 'small', assemblySize: 'default',
language: '', language: '',
themeConfig: { themeConfig: {
panelName: '', panelName: '',

View File

@ -1,6 +1,5 @@
import { RouteRecordRaw } from 'vue-router'; import { RouteRecordRaw } from 'vue-router';
/* themeConfigProp */
export interface ThemeConfigProp { export interface ThemeConfigProp {
panelName: string; panelName: string;
primary: string; primary: string;
@ -8,7 +7,6 @@ export interface ThemeConfigProp {
footer: boolean; footer: boolean;
} }
/* GlobalState */
export interface GlobalState { export interface GlobalState {
isLogin: boolean; isLogin: boolean;
csrfToken: string; csrfToken: string;
@ -22,7 +20,6 @@ export interface MenuState {
menuList: RouteRecordRaw[]; menuList: RouteRecordRaw[];
} }
/* AuthState */
export interface AuthState { export interface AuthState {
authRouter: string[]; authRouter: string[];
} }