# Alou Pay Nginx 配置文件
# 放置在 /etc/nginx/sites-available/alou-pay
server {
listen 80;
server_name 140.179.186.11 localhost;
# 启用 gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
# 前端静态文件
location / {
root /opt/alou-pay/frontend;
try_files $uri $uri/ /index.html;
index index.html;
# 缓存静态资源
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# HTML 文件不缓存
location ~* \.html$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
}
# API 代理到 Rust 后端
location /api/ {
proxy_pass http://127.0.0.1:3001;
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;
proxy_cache_bypass $http_upgrade;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# CORS 头部
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
if ($request_method = 'OPTIONS') {
return 204;
}
}
# 健康检查端点
location /health {
proxy_pass http://127.0.0.1:3001/api/health;
access_log off;
# 健康检查不需要缓存
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 安全头部
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline' 'unsafe-eval'" always;
# 日志配置
access_log /var/log/nginx/alou-pay.access.log;
error_log /var/log/nginx/alou-pay.error.log;
# 限制请求大小
client_max_body_size 10M;
}
# HTTP 重定向到 HTTPS (如果以后需要 SSL)
# server {
# listen 80;
# server_name 140.179.186.11;
# return 301 https://$server_name$request_uri;
# }