更新
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
# Nginx HTTPS 生产环境配置
|
||||
# 域名: api.zzzhengyangtang.cn
|
||||
|
||||
# HTTPS 服务器配置 (管理后台)
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name api.zzzhengyangtang.cn;
|
||||
|
||||
# SSL 证书配置 (使用 Let's Encrypt)
|
||||
ssl_certificate /etc/letsencrypt/live/api.zzzhengyangtang.cn/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/api.zzzhengyangtang.cn/privkey.pem;
|
||||
|
||||
# SSL 安全配置
|
||||
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';
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# HSTS (强制使用 HTTPS)
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# 安全头部
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# 管理后台静态文件
|
||||
location /admin {
|
||||
alias /path/to/your/server/public/admin; # 修改为实际路径
|
||||
try_files $uri $uri/ /admin/index.html;
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
|
||||
# API 代理
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:8000; # 修改为实际的后端端口
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# WebSocket 支持
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# 超时设置
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# 日志配置
|
||||
access_log /var/log/nginx/admin_https_access.log;
|
||||
error_log /var/log/nginx/admin_https_error.log;
|
||||
}
|
||||
|
||||
# HTTP 自动重定向到 HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
server_name api.zzzhengyangtang.cn;
|
||||
|
||||
# Let's Encrypt 验证路径
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
# 其他所有请求重定向到 HTTPS
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user