add
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
# 生产阶段:使用指定版本的 Nginx Alpine 镜像(大小写统一)
|
||||
FROM nginx:1.29.3-alpine AS production-stage
|
||||
|
||||
# 清除 Nginx 默认静态文件
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
|
||||
# 复制项目所有文件到 Nginx 静态文件目录(适配你的项目结构)
|
||||
COPY . /usr/share/nginx/html
|
||||
|
||||
# 复制自定义 Nginx 配置(解决 SPA 路由刷新 404 问题,必须添加)
|
||||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 暴露 80 端口
|
||||
EXPOSE 80
|
||||
|
||||
# 启动 Nginx(前台运行)
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -12,7 +12,7 @@ window.MenuConfig = [
|
||||
id: 'country',
|
||||
icon: '🌎',
|
||||
title: '国家管理',
|
||||
url: 'modules/country.html'
|
||||
url: 'country.html'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html; # 入口文件指向项目根目录的 index.html
|
||||
|
||||
# 支持 SPA 路由重写(关键:解决刷新404)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
add_header Cache-Control "no-cache"; # 入口文件不缓存
|
||||
}
|
||||
|
||||
# 静态资源缓存配置(JS/CSS/图片等)
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|otf)$ {
|
||||
expires 7d; # 缓存7天
|
||||
add_header Cache-Control "public, max-age=604800";
|
||||
add_header Access-Control-Allow-Origin "*"; # 允许跨域(可选)
|
||||
}
|
||||
|
||||
# 禁止访问隐藏文件(如 .git、.env 等)
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# 优化 Nginx 响应速度
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
# 关闭不必要的日志
|
||||
access_log off;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
}
|
||||
Reference in New Issue
Block a user