From 14b24c215a952c2af505e0a22aeae00e74c203bd Mon Sep 17 00:00:00 2001 From: zyj <18107291228@163.com> Date: Sat, 22 Nov 2025 17:48:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9nginx=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/nginx_template.go | 93 ++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/types/nginx_template.go b/types/nginx_template.go index 0bb5e1c..c6b1f30 100644 --- a/types/nginx_template.go +++ b/types/nginx_template.go @@ -1,33 +1,66 @@ package types -const NGINX_CONF_TMP = `server { - listen {{.Port}}; - server_name {{.Host}}; - root "{{.FilePath}}"; - location / { - index index.php index.html; - error_page 400 /error/400.html; - error_page 403 /error/403.html; - error_page 404 /error/404.html; - error_page 500 /error/500.html; - error_page 501 /error/501.html; - error_page 502 /error/502.html; - error_page 503 /error/503.html; - error_page 504 /error/504.html; - error_page 505 /error/505.html; - error_page 506 /error/506.html; - error_page 507 /error/507.html; - error_page 509 /error/509.html; - error_page 510 /error/510.html; - autoindex off; - } - location ~ \.php(.*)$ { - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; - fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; - include fastcgi_params; - } +const NGINX_CONF_TMP = `# Nginx 配置 - {{.SiteName}} +# 生成时间: {{.CreateTime}} + +server { + listen {{.Port}}; + server_name {{.Host}}; + root "{{.FilePath}}"; + index {{.Index}}; + + # 字符编码 + charset utf-8; + + # 访问日志 + access_log logs/{{.SiteName}}_access.log combined; + error_log logs/{{.SiteName}}_error.log warn; + + # 文件上传限制 + client_max_body_size 50m; + + # Gzip 压缩 + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json; + + # 静态文件缓存 + location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { + expires 7d; + add_header Cache-Control "public, immutable"; + } + + # 主路由 + location / { + try_files $uri $uri/ /{{.Index}}; + autoindex off; + } + + # 错误页面 + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # 禁止访问隐藏文件 + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } + + # PHP 支持(如果需要) + location ~ \.php$ { + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + # 禁止访问备份文件 + location ~* \.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)$ { + deny all; + } }`