diff --git a/Dockerfile b/Dockerfile index ee03884..e0482a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,7 +63,7 @@ RUN if [ "${NODE_ENV}" = "production" ]; then \ FROM nginx:stable-alpine as production-stage # 安装基础工具 -RUN apk add --no-cache bash curl +RUN apk add --no-cache bash curl net-tools iputils # 创建必要的目录并设置权限 RUN mkdir -p /var/cache/nginx/client_temp && \ @@ -95,6 +95,16 @@ RUN chown -R nginx:nginx /var/cache/nginx && \ chmod -R 755 /usr/share/nginx/html && \ chmod -R 755 /etc/nginx/conf.d +# 创建启动脚本 +RUN echo '#!/bin/sh\n\ +echo "=== 容器网络信息 ==="\n\ +ip addr\n\ +echo "=== Nginx 配置检查 ==="\n\ +nginx -t\n\ +echo "=== 启动 Nginx ==="\n\ +nginx -g "daemon off;"\n\ +' > /start.sh && chmod +x /start.sh + # 暴露端口 EXPOSE 80 @@ -102,4 +112,4 @@ EXPOSE 80 USER root # 启动nginx -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["/start.sh"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index d68e7a4..1bfed50 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,6 +1,6 @@ server { listen 80; - server_name localhost; + server_name localhost _; # 添加通配符,接受任何域名 # 添加 gzip 压缩 gzip on; @@ -16,6 +16,10 @@ server { location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache, no-store, must-revalidate"; + # 添加跨域支持 + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; } # 缓存静态资源