feat: 添加Docker部署配置和文档

- 创建docker-compose.yml多容器编排配置
- 创建Dockerfile多阶段构建配置
- 创建nginx.conf反向代理和SSL配置
- 创建.env.example环境变量示例文件
- 创建setup-ssl.sh SSL证书配置脚本
- 创建deploy.sh自动化部署脚本
- 创建DEPLOYMENT.md详细部署文档
- 配置容器名称为novalon-website,版本1.0.0
- 配置端口映射80和443
- 配置Let's Encrypt免费SSL证书
- 配置域名novalon.cn,服务器IP 139.155.109.62
- 配置ICP备案号:蜀ICP备2026013658号
This commit is contained in:
张翔
2026-03-26 19:27:18 +08:00
parent b26cf5b451
commit ece3c86e29
7 changed files with 799 additions and 180 deletions
+73 -85
View File
@@ -1,86 +1,75 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
use epoll;
multi_accept on;
worker_connections 1024;
}
http {
upstream backend {
least_conn;
server app1:3001 max_fails=3 fail_timeout=30s;
server app2:3002 max_fails=3 fail_timeout=30s;
server app3:3003 max_fails=3 fail_timeout=30s;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 20M;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+text text/javascript;
upstream novalon_app {
server novalon-website:3000;
}
# 缓存配置
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=app_cache:10m max_size=1g inactive=60m use_temp_path=off;
# 限流配置
limit_req_zone $binary_remote_addr zone=general:10m rate=100r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
listen 80;
server_name _;
server_name novalon.cn www.novalon.cn;
# 健康检查端点
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# 静态资源缓存
location /_next/static/ {
proxy_pass http://backend;
proxy_cache app_cache;
proxy_cache_valid 200 365d;
proxy_cache_use_stale error timeout updating;
add_header X-Cache-Status $upstream_cache_status;
expires 365d;
add_header Cache-Control "public, immutable";
}
# 图片资源缓存
location ~* \.(jpg|jpeg|png|gif|webp|avif|svg|ico)$ {
proxy_pass http://backend;
proxy_cache app_cache;
proxy_cache_valid 200 365d;
proxy_cache_use_stale error timeout updating;
add_header X-Cache-Status $upstream_cache_status;
expires 365d;
add_header Cache-Control "public, immutable";
}
# API 路由
location /api/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;
# API 缓存
proxy_cache app_cache;
proxy_cache_valid 200 5m;
proxy_cache_methods GET HEAD;
proxy_cache_bypass $http_pragma $http_authorization;
# 连接超时
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# 主应用路由
location / {
limit_req zone=general burst=200 nodelay;
limit_conn addr 10;
proxy_pass http://backend;
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
server_name novalon.cn www.novalon.cn;
ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
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 / {
proxy_pass http://novalon_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
@@ -88,24 +77,23 @@ http {
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;
# 缓冲配置
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 4k;
proxy_busy_buffers_size 8k;
# 连接超时
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Gzip 压缩
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
location /_next/static {
proxy_pass http://novalon_app;
proxy_cache_valid 200 60m;
add_header Cache-Control "public, immutable, max-age=31536000, s-maxage=31536000";
}
location /static {
proxy_pass http://novalon_app;
proxy_cache_valid 200 60m;
add_header Cache-Control "public, immutable, max-age=31536000, s-maxage=31536000";
}
}
}