admin-vue3/nginx.conf

124 lines
4.1 KiB
Nginx Configuration File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Nginx 配置文件 - 前后端同服务器部署
# 适用于 Vue3 前端 + 后端 API 部署在同一台服务器
server {
listen 3080; # 前端服务端口
# 请根据实际情况修改域名,如果没有域名可以使用服务器IP
server_name your-domain.com; # 修改为你的域名或服务器IP
# 前端静态文件根目录 - 构建后的 dist 目录
root /var/www/ncc-ui-admin-vue3/dist; # 修改为实际的部署路径
index index.html;
# 开启 gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
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;
gzip_disable "msie6";
# 静态资源缓存策略
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 7d;
add_header Cache-Control "public, immutable";
access_log off;
}
# 后端 API 代理配置
location /admin-api/ {
# 代理到后端服务,请根据实际后端端口修改
proxy_pass http://localhost:48080/admin-api/; # 修改为实际的后端地址和端口
# 代理请求头设置
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 支持(如果后端有 WebSocket 需求)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 超时设置
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
# 请求体大小限制(根据需要调整,例如文件上传)
client_max_body_size 100M;
}
# 对象存储代理配置
# 正式环境建议通过 Nginx 代理 MinIO保持前端页面与上传地址同源避免浏览器跨域限制
location /ncc-dev/ {
proxy_pass http://localhost:9000; # 修改为实际的 MinIO 地址和端口,保留原始 bucket 路径避免预签名失效
proxy_set_header Host $http_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;
# 大文件直传时关闭请求缓冲,避免 Nginx 先完整落盘再转发
proxy_request_buffering off;
proxy_buffering off;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
client_max_body_size 600M;
}
# 前端路由配置 - Vue Router history 模式支持
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 安全头部设置
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# HTTPS 配置示例(如果需要 SSL 证书)
# server {
# listen 443 ssl http2;
# server_name your-domain.com;
#
# # SSL 证书路径
# ssl_certificate /path/to/your/certificate.crt;
# ssl_certificate_key /path/to/your/private.key;
#
# # SSL 配置
# 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;
#
# # 其他配置与上面的 HTTP 配置相同
# root /var/www/ncc-ui-admin-vue3/dist;
# index index.html;
#
# # ... 复制上面的 location 配置 ...
# }
#
# # HTTP 自动跳转到 HTTPS
# server {
# listen 80;
# server_name your-domain.com;
# return 301 https://$server_name$request_uri;
# }