98 lines
3.2 KiB
Plaintext
98 lines
3.2 KiB
Plaintext
|
|
# Nginx 前端代理配置
|
||
|
|
# 部署在 gvizee.com 服务器上
|
||
|
|
# 将 /api/ 请求代理到后端 HTTP 服务
|
||
|
|
|
||
|
|
server {
|
||
|
|
listen 80;
|
||
|
|
server_name gvizee.com www.gvizee.com;
|
||
|
|
|
||
|
|
# 重定向到 HTTPS
|
||
|
|
return 301 https://$server_name$request_uri;
|
||
|
|
}
|
||
|
|
|
||
|
|
server {
|
||
|
|
listen 443 ssl http2;
|
||
|
|
server_name gvizee.com www.gvizee.com;
|
||
|
|
|
||
|
|
# SSL 证书配置(使用你现有的证书)
|
||
|
|
ssl_certificate /etc/letsencrypt/live/gvizee.com/fullchain.pem;
|
||
|
|
ssl_certificate_key /etc/letsencrypt/live/gvizee.com/privkey.pem;
|
||
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||
|
|
|
||
|
|
# 静态文件根目录
|
||
|
|
root /var/www/gvizee.com;
|
||
|
|
index index.html;
|
||
|
|
|
||
|
|
# 前端静态文件
|
||
|
|
location / {
|
||
|
|
try_files $uri $uri/ /index.html;
|
||
|
|
}
|
||
|
|
|
||
|
|
# API 反向代理到后端 HTTP 服务
|
||
|
|
location /api/ {
|
||
|
|
# 代理到后端服务器
|
||
|
|
proxy_pass http://104.244.91.212:8060;
|
||
|
|
|
||
|
|
# 设置代理头
|
||
|
|
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_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, PUT, DELETE, OPTIONS' always;
|
||
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||
|
|
|
||
|
|
# 处理 OPTIONS 预检请求
|
||
|
|
if ($request_method = 'OPTIONS') {
|
||
|
|
add_header 'Access-Control-Allow-Origin' '*';
|
||
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
|
||
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
|
||
|
|
add_header 'Access-Control-Max-Age' 1728000;
|
||
|
|
add_header 'Content-Type' 'text/plain; charset=utf-8';
|
||
|
|
add_header 'Content-Length' 0;
|
||
|
|
return 204;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# health 端点代理
|
||
|
|
location /health {
|
||
|
|
proxy_pass http://104.244.91.212:8060;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# ====================================
|
||
|
|
# 部署步骤:
|
||
|
|
# ====================================
|
||
|
|
# 1. 上传此配置到 gvizee.com 服务器
|
||
|
|
# scp nginx-frontend-proxy.conf user@gvizee.com:/tmp/
|
||
|
|
#
|
||
|
|
# 2. SSH 登录服务器
|
||
|
|
# ssh user@gvizee.com
|
||
|
|
#
|
||
|
|
# 3. 复制配置文件
|
||
|
|
# sudo cp /tmp/nginx-frontend-proxy.conf /etc/nginx/sites-available/gvizee.com
|
||
|
|
# sudo ln -sf /etc/nginx/sites-available/gvizee.com /etc/nginx/sites-enabled/
|
||
|
|
#
|
||
|
|
# 4. 测试配置
|
||
|
|
# sudo nginx -t
|
||
|
|
#
|
||
|
|
# 5. 重启 Nginx
|
||
|
|
# sudo systemctl restart nginx
|
||
|
|
#
|
||
|
|
# ====================================
|
||
|
|
# 注意事项:
|
||
|
|
# ====================================
|
||
|
|
# - SSL 证书路径需要根据实际情况修改
|
||
|
|
# - 如果没有 SSL 证书,使用 Let's Encrypt 免费申请:
|
||
|
|
# sudo certbot --nginx -d gvizee.com -d www.gvizee.com
|
||
|
|
# - 确保后端服务器允许来自 gvizee.com 的请求
|