diff --git a/internal/data/website.go b/internal/data/website.go index 2cd3b6c2..de4b9d5f 100644 --- a/internal/data/website.go +++ b/internal/data/website.go @@ -224,7 +224,11 @@ func (r *websiteRepo) List(page, limit uint) ([]*biz.Website, int64, error) { func (r *websiteRepo) Create(req *request.WebsiteCreate) (*biz.Website, error) { // 初始化nginx配置 - p, err := nginx.NewParser() + config := nginx.DefaultConf + if app.Locale == "zh_CN" { + config = nginx.DefaultConfZh + } + p, err := nginx.NewParser(config) if err != nil { return nil, err } @@ -609,7 +613,11 @@ func (r *websiteRepo) ResetConfig(id uint) error { } // 初始化nginx配置 - p, err := nginx.NewParser() + config := nginx.DefaultConf + if app.Locale == "zh_CN" { + config = nginx.DefaultConfZh + } + p, err := nginx.NewParser(config) if err != nil { return err } diff --git a/pkg/nginx/data.go b/pkg/nginx/data.go index 455a8892..f0a2457d 100644 --- a/pkg/nginx/data.go +++ b/pkg/nginx/data.go @@ -4,35 +4,7 @@ var order = []string{"listen", "server_name", "index", "root", "ssl_certificate", "ssl_certificate_key", "ssl_session_timeout", "ssl_session_cache", "ssl_protocols", "ssl_ciphers", "ssl_prefer_server_ciphers", "ssl_early_data", "ssl_stapling", "ssl_stapling_verify", "ssl_trusted_certificate", "resolver", "error_page", "include", "if", "location", "add_header", "access_log", "error_log"} -const defaultConf = `server { - listen 80; - server_name localhost; - index index.php index.html index.htm; - root /www/wwwroot/default; - # 错误页配置 - error_page 404 /404.html; - include enable-php-0.conf; - # 不记录静态文件日志 - location ~ .*\.(bmp|jpg|jpeg|png|gif|svg|ico|tiff|webp|avif|heif|heic|jxl)$ { - expires 30d; - access_log /dev/null; - error_log /dev/null; - } - location ~ .*\.(js|css|ttf|otf|woff|woff2|eot)$ { - expires 6h; - access_log /dev/null; - error_log /dev/null; - } - # 禁止部分敏感目录 - location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.env) { - return 404; - } - access_log /www/wwwlogs/default.log; - error_log /www/wwwlogs/default.log; -} -` - -const defaultConfEn = `server { +const DefaultConf = `server { listen 80; server_name localhost; index index.php index.html index.htm; @@ -59,3 +31,31 @@ const defaultConfEn = `server { error_log /www/wwwlogs/default.log; } ` + +const DefaultConfZh = `server { + listen 80; + server_name localhost; + index index.php index.html index.htm; + root /www/wwwroot/default; + # 错误页配置 + error_page 404 /404.html; + include enable-php-0.conf; + # 不记录静态文件日志 + location ~ .*\.(bmp|jpg|jpeg|png|gif|svg|ico|tiff|webp|avif|heif|heic|jxl)$ { + expires 30d; + access_log /dev/null; + error_log /dev/null; + } + location ~ .*\.(js|css|ttf|otf|woff|woff2|eot)$ { + expires 6h; + access_log /dev/null; + error_log /dev/null; + } + # 禁止部分敏感目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.env) { + return 404; + } + access_log /www/wwwlogs/default.log; + error_log /www/wwwlogs/default.log; +} +` diff --git a/pkg/nginx/parser.go b/pkg/nginx/parser.go index f9e79b9d..d285d3d1 100644 --- a/pkg/nginx/parser.go +++ b/pkg/nginx/parser.go @@ -18,7 +18,7 @@ type Parser struct { func NewParser(str ...string) (*Parser, error) { if len(str) == 0 { - str = append(str, defaultConf) + str = append(str, DefaultConf) } p := parser.NewStringParser(str[0], parser.WithSkipIncludeParsingErr(), parser.WithSkipValidDirectivesErr()) c, err := p.Parse()