From 525cb154ca858cedc73d8deeb5c57ef2528b5c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 27 Jul 2023 15:52:25 +0800 Subject: [PATCH] fix(website): ssl problem --- app/http/controllers/website_controller.go | 10 +++++----- app/services/website.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/http/controllers/website_controller.go b/app/http/controllers/website_controller.go index 8f8a66ee..2489993b 100644 --- a/app/http/controllers/website_controller.go +++ b/app/http/controllers/website_controller.go @@ -335,9 +335,9 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { // SSL ssl := ctx.Request().InputBool("ssl") website.Ssl = ssl + tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".pem", ctx.Request().Input("ssl_certificate"), 0644) + tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".key", ctx.Request().Input("ssl_certificate_key"), 0644) if ssl { - tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".pem", ctx.Request().Input("ssl_certificate"), 0644) - tools.WriteFile("/www/server/vhost/ssl/"+website.Name+".key", ctx.Request().Input("ssl_certificate_key"), 0644) sslConfig := `# ssl标记位开始 ssl_certificate /www/server/vhost/ssl/` + website.Name + `.pem; ssl_certificate_key /www/server/vhost/ssl/` + website.Name + `.key; @@ -350,10 +350,10 @@ func (c *WebsiteController) SaveConfig(ctx http.Context) { ` if ctx.Request().InputBool("http_redirect") { sslConfig += `# http重定向标记位开始 - if (\$server_port !~ 443){ - return 301 https://\$host\$request_uri; + if ($server_port !~ 443){ + return 301 https://$host$request_uri; } - error_page 497 https://\$host\$request_uri; + error_page 497 https://$host$request_uri; # http重定向标记位结束 ` } diff --git a/app/services/website.go b/app/services/website.go index bf3d0bc9..ef9da4a6 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -231,10 +231,10 @@ server rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword) if website.Db && website.DbType == "mysql" { - tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE DATABASE IF NOT EXISTS " + website.DbName + " DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;\"") - tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"CREATE USER '" + website.DbUser + "'@'localhost' IDENTIFIED BY '" + website.DbPassword + "';\"") - tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"GRANT ALL PRIVILEGES ON " + website.DbName + ".* TO '" + website.DbUser + "'@'localhost';\"") - tools.ExecShell("mysql -uroot -p" + rootPassword + " -e \"FLUSH PRIVILEGES;\"") + tools.ExecShell(`/www/server/mysql/bin/mysql -uroot -p` + rootPassword + ` -e "CREATE DATABASE IF NOT EXISTS ` + website.DbName + ` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;"`) + tools.ExecShell(`/www/server/mysql/bin/mysql -uroot -p` + rootPassword + ` -e "CREATE USER '` + website.DbUser + `'@'localhost' IDENTIFIED BY '` + website.DbPassword + `';"`) + tools.ExecShell(`/www/server/mysql/bin/mysql -uroot -p` + rootPassword + ` -e "GRANT ALL PRIVILEGES ON ` + website.DbName + `.* TO '` + website.DbUser + `'@'localhost';"`) + tools.ExecShell(`/www/server/mysql/bin/mysql -uroot -p` + rootPassword + ` -e "FLUSH PRIVILEGES;"`) } return w, nil