64 lines
2.1 KiB
Nginx Configuration File
64 lines
2.1 KiB
Nginx Configuration File
# 东燊科技宣传站 — Nginx 参考配置(大陆云主机 / 自建)
|
||||
|
|
# 用法:将本文件 server 块并入站点 nginx.conf(或 conf.d/),
|
|||
|
|
# 修改 server_name、ssl 证书路径、root 指向站点目录(本 web/ 目录)。
|
|||
|
|
# 纯静态站,无需 PHP/Node 反代。
|
|||
|
|
|
|||
|
|
server {
|
|||
|
|
listen 80;
|
|||
|
|
server_name www.您的域名.com 您的域名.com;
|
|||
|
|
# HTTP 强制跳 HTTPS
|
|||
|
|
return 301 https://$host$request_uri;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
server {
|
|||
|
|
listen 443 ssl http2;
|
|||
|
|
server_name www.您的域名.com 您的域名.com;
|
|||
|
|
|
|||
|
|
# ssl_certificate /etc/nginx/ssl/您的域名.pem;
|
|||
|
|
# ssl_certificate_key /etc/nginx/ssl/您的域名.key;
|
|||
|
|
# ssl_protocols TLSv1.2 TLSv1.3;
|
|||
|
|
# ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
|
|||
|
|
# ssl_prefer_server_ciphers off;
|
|||
|
|
# ssl_session_cache shared:SSL:10m;
|
|||
|
|
# ssl_session_timeout 1d;
|
|||
|
|
|
|||
|
|
root /var/www/donsen-web; # ← 改为本 web/ 目录实际路径
|
|||
|
|
index index.html;
|
|||
|
|
|
|||
|
|
# ---------- 压缩:gzip(文本再省 ~72%)----------
|
|||
|
|
gzip on;
|
|||
|
|
gzip_vary on;
|
|||
|
|
gzip_proxied any;
|
|||
|
|
gzip_comp_level 6;
|
|||
|
|
gzip_min_length 256;
|
|||
|
|
gzip_types text/plain text/css text/html application/javascript application/json image/svg+xml;
|
|||
|
|
|
|||
|
|
# ---------- 安全响应头 ----------
|
|||
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|||
|
|
add_header X-Frame-Options "DENY" always;
|
|||
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|||
|
|
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
|||
|
|
|
|||
|
|
# ---------- 缓存策略 ----------
|
|||
|
|
location ~* \.(?:css|js|png|webp|jpg|jpeg|svg|ico)$ {
|
|||
|
|
expires 1y;
|
|||
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|||
|
|
}
|
|||
|
|
location ~* \.(?:html|txt)$ {
|
|||
|
|
add_header Cache-Control "no-cache";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# ---------- 单页路由 ----------
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ /index.html;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 404 页
|
|||
|
|
error_page 404 /404.html;
|
|||
|
|
|
|||
|
|
# 屏蔽隐藏文件(如 .htaccess / .git)
|
|||
|
|
location ~ /\. {
|
|||
|
|
deny all;
|
|||
|
|
}
|
|||
|
|
}
|