# Nginx 反向代理配置範例 (含 SSL) # 放置位置:/etc/nginx/sites-available/codimd # HTTP - 自動重定向到 HTTPS server { listen 80; listen [::]:80; server_name your-domain.com; # Let's Encrypt 驗證目錄 location /.well-known/acme-challenge/ { root /var/www/certbot; } # 其他 HTTP 流量重定向到 HTTPS location / { return 301 https://$server_name$request_uri; } } # HTTPS - 主要服務 server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name your-domain.com; # SSL 證書配置 (Let's Encrypt) ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your-domain.com/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:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_session_tickets off; # HSTS (HTTP Strict Transport Security) add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" 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; add_header Referrer-Policy "no-referrer-when-downgrade" always; # 用戶端上傳大小限制 client_max_body_size 50M; # 反向代理到 CodiMD location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; # WebSocket 支援 (CodiMD 即時協作需要) 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; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; # 超時設定 proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; # 緩衝設定 proxy_buffering off; proxy_request_buffering off; } # 健康檢查端點 (可選) location /health { access_log off; proxy_pass http://127.0.0.1:3000; } }