1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +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)
}
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)
if err != nil {
return err
@ -144,8 +144,8 @@ func deleteNginxConfig(scope string, keys []string, website *model.Website) erro
block = config.Config.Block
}
for _, key := range keys {
block.RemoveDirective(key, []string{})
for _, param := range params {
block.RemoveDirective(param.Name, param.Params)
}
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
}
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)
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 {
return response.WebsiteHTTPS{}, err
}
keys := getKeysFromStaticFile(dto.SSL)
keys = append(keys, "if")
if err := deleteNginxConfig(constant.NginxScopeServer, keys, &website); err != nil {
nginxParams := getNginxParamsFromStaticFile(dto.SSL, nil)
nginxParams = append(nginxParams, dto.NginxParam{
Name: "if",
Params: []string{"($scheme", "=", "http)"},
})
if err := deleteNginxConfig(constant.NginxScopeServer, nginxParams, &website); err != nil {
return response.WebsiteHTTPS{}, err
}
if err := websiteRepo.Save(ctx, &website); err != nil {
@ -771,7 +780,12 @@ func (w WebsiteService) OpWebsiteLog(req request.WebsiteLogReq) (*response.Websi
key = "error_log"
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
}
if err := websiteRepo.Save(context.Background(), &website); err != nil {

View File

@ -39,9 +39,11 @@ func (c *Config) FindHttp() *Http {
var repeatKeys = map[string]struct {
}{
"limit_conn": {},
"limit_conn_zone": {},
"set": {},
"limit_conn": {},
"limit_conn_zone": {},
"set": {},
"if": {},
"proxy_set_header": {},
}
func IsRepeatKey(key string) bool {

View File

@ -277,4 +277,5 @@ func (s *Server) AddHTTP2HTTPS() {
})
newDir.Block = block
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
var SSL []byte
//go:embed http2https.conf
var HTTPS []byte
//go:embed website_default.conf
var WebsiteDefault []byte
@ -18,6 +15,3 @@ var Limit []byte
//go:embed index.html
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;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;

View File

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

View File

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

View File

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

View File

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