128 lines
4.1 KiB
Plaintext
128 lines
4.1 KiB
Plaintext
# Nginx 配置示例
|
||
# 用于部署 H5 版本的芋道管理后台移动端
|
||
|
||
# 情况一:部署在根目录(推荐)
|
||
server {
|
||
listen 80;
|
||
server_name your-domain.com; # 修改为您的域名或 IP
|
||
|
||
# 网站根目录,指向构建后的 dist/build/h5 目录
|
||
root /path/to/your/project/dist/build/h5; # 修改为实际路径
|
||
index index.html;
|
||
|
||
# 启用 gzip 压缩
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_min_length 1024;
|
||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript;
|
||
|
||
# 静态资源缓存
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
}
|
||
|
||
# API 代理配置(如果需要)
|
||
# 如果后端 API 需要代理,取消下面的注释并修改配置
|
||
# location /api/ {
|
||
# proxy_pass http://your-backend-server:port;
|
||
# 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;
|
||
#
|
||
# # CORS 配置(如果需要)
|
||
# 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';
|
||
#
|
||
# if ($request_method = 'OPTIONS') {
|
||
# return 204;
|
||
# }
|
||
# }
|
||
|
||
# Vue Router History 模式支持
|
||
# 所有路由都指向 index.html,由前端路由处理
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
|
||
# 安全配置
|
||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||
add_header X-Content-Type-Options "nosniff" always;
|
||
add_header X-XSS-Protection "1; mode=block" always;
|
||
}
|
||
|
||
# 情况二:部署在子目录(如 /app/)
|
||
# 如果您的应用需要部署在子目录下,使用以下配置
|
||
# 同时需要在 env/.env.production 中设置 VITE_APP_PUBLIC_BASE=/app/
|
||
server {
|
||
listen 80;
|
||
server_name your-domain.com; # 修改为您的域名或 IP
|
||
|
||
# 网站根目录
|
||
root /path/to/your/web/root; # 修改为实际路径
|
||
index index.html;
|
||
|
||
# 启用 gzip 压缩
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_min_length 1024;
|
||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript;
|
||
|
||
# 静态资源缓存
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
}
|
||
|
||
# 子目录部署
|
||
location /app/ {
|
||
alias /path/to/your/project/dist/build/h5/; # 修改为实际路径
|
||
try_files $uri $uri/ /app/index.html;
|
||
index index.html;
|
||
}
|
||
|
||
# API 代理配置(如果需要)
|
||
# location /api/ {
|
||
# proxy_pass http://your-backend-server:port;
|
||
# 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;
|
||
# }
|
||
|
||
# 安全配置
|
||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||
add_header X-Content-Type-Options "nosniff" always;
|
||
add_header X-XSS-Protection "1; mode=block" always;
|
||
}
|
||
|
||
# HTTPS 配置示例(推荐生产环境使用)
|
||
# server {
|
||
# listen 443 ssl http2;
|
||
# server_name your-domain.com;
|
||
#
|
||
# # SSL 证书配置
|
||
# ssl_certificate /path/to/your/cert.pem;
|
||
# ssl_certificate_key /path/to/your/key.pem;
|
||
#
|
||
# # SSL 优化配置
|
||
# ssl_protocols TLSv1.2 TLSv1.3;
|
||
# ssl_ciphers HIGH:!aNULL:!MD5;
|
||
# ssl_prefer_server_ciphers on;
|
||
#
|
||
# root /path/to/your/project/dist/build/h5;
|
||
# index index.html;
|
||
#
|
||
# # 其他配置同上面的 HTTP 配置
|
||
# # ...
|
||
# }
|
||
#
|
||
# # HTTP 重定向到 HTTPS
|
||
# server {
|
||
# listen 80;
|
||
# server_name your-domain.com;
|
||
# return 301 https://$server_name$request_uri;
|
||
# }
|