diff --git a/Dockerfile b/Dockerfile index 5e56c84..ff86604 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,9 @@ RUN pnpm build # Stage 2: Serve with Nginx FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine +# Copy custom Nginx configuration +COPY nginx.conf /etc/nginx/nginx.conf + # Copy built assets from builder stage COPY --from=builder /app/dist /usr/share/nginx/html diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..4392d4a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,41 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + # Explicitly add support for .mjs files + types { + application/javascript mjs; + } + + sendfile on; + keepalive_timeout 65; + + server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + # Cache control for static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|mjs)$ { + root /usr/share/nginx/html; + expires 1y; + add_header Cache-Control "public, no-transform"; + } + + # Error pages + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +}