91 lines
2.7 KiB
Docker
91 lines
2.7 KiB
Docker
|
|
# 使用阿里云镜像加速
|
||
|
|
FROM registry.cn-hangzhou.aliyuncs.com/library/nginx:alpine
|
||
|
|
|
||
|
|
# 设置维护者信息
|
||
|
|
LABEL maintainer="AIEC <support@aiec.com>"
|
||
|
|
LABEL description="云大阁AI对话平台前端服务"
|
||
|
|
LABEL version="1.0.0"
|
||
|
|
|
||
|
|
# 设置工作目录
|
||
|
|
WORKDIR /usr/share/nginx/html
|
||
|
|
|
||
|
|
# 复制所有前端文件到Nginx目录
|
||
|
|
COPY index.html ./
|
||
|
|
COPY config.js ./
|
||
|
|
COPY css/ ./css/
|
||
|
|
COPY js/ ./js/
|
||
|
|
COPY images/ ./images/
|
||
|
|
COPY auth/ ./auth/
|
||
|
|
COPY services/ ./services/
|
||
|
|
COPY utils/ ./utils/
|
||
|
|
COPY config/ ./config/
|
||
|
|
COPY docs/ ./docs/
|
||
|
|
|
||
|
|
# 创建Nginx配置
|
||
|
|
RUN echo 'server { \
|
||
|
|
listen 80; \
|
||
|
|
server_name localhost; \
|
||
|
|
charset utf-8; \
|
||
|
|
root /usr/share/nginx/html; \
|
||
|
|
index index.html; \
|
||
|
|
client_max_body_size 20M; \
|
||
|
|
\
|
||
|
|
# 开启gzip压缩 \
|
||
|
|
gzip on; \
|
||
|
|
gzip_vary on; \
|
||
|
|
gzip_min_length 1024; \
|
||
|
|
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml application/atom+xml image/svg+xml text/javascript application/x-javascript application/x-font-ttf application/vnd.ms-fontobject font/opentype; \
|
||
|
|
\
|
||
|
|
# 安全头 \
|
||
|
|
add_header X-Frame-Options "SAMEORIGIN" always; \
|
||
|
|
add_header X-Content-Type-Options "nosniff" always; \
|
||
|
|
add_header X-XSS-Protection "1; mode=block" always; \
|
||
|
|
\
|
||
|
|
# 处理前端路由 \
|
||
|
|
location / { \
|
||
|
|
try_files $uri $uri/ /index.html; \
|
||
|
|
add_header Access-Control-Allow-Origin *; \
|
||
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"; \
|
||
|
|
add_header Access-Control-Allow-Headers "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization"; \
|
||
|
|
} \
|
||
|
|
\
|
||
|
|
# 静态资源缓存 \
|
||
|
|
location ~* \.(jpg|jpeg|png|gif|ico|svg)$ { \
|
||
|
|
expires 7d; \
|
||
|
|
add_header Cache-Control "public, immutable"; \
|
||
|
|
access_log off; \
|
||
|
|
} \
|
||
|
|
\
|
||
|
|
location ~* \.(css|js)$ { \
|
||
|
|
expires 1d; \
|
||
|
|
add_header Cache-Control "public"; \
|
||
|
|
access_log off; \
|
||
|
|
} \
|
||
|
|
\
|
||
|
|
location ~* \.(woff|woff2|ttf|eot)$ { \
|
||
|
|
expires 30d; \
|
||
|
|
add_header Cache-Control "public, immutable"; \
|
||
|
|
access_log off; \
|
||
|
|
} \
|
||
|
|
\
|
||
|
|
# 健康检查 \
|
||
|
|
location /health { \
|
||
|
|
access_log off; \
|
||
|
|
return 200 "healthy\n"; \
|
||
|
|
add_header Content-Type text/plain; \
|
||
|
|
} \
|
||
|
|
}' > /etc/nginx/conf.d/default.conf
|
||
|
|
|
||
|
|
# 设置文件权限
|
||
|
|
RUN chmod -R 755 /usr/share/nginx/html && \
|
||
|
|
chmod 644 /etc/nginx/conf.d/default.conf
|
||
|
|
|
||
|
|
# 暴露端口
|
||
|
|
EXPOSE 80
|
||
|
|
|
||
|
|
# 健康检查
|
||
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||
|
|
CMD wget -q --spider http://localhost/health || exit 1
|
||
|
|
|
||
|
|
# 启动Nginx
|
||
|
|
CMD ["nginx", "-g", "daemon off;"]
|