Add Docker deployment configuration
- Dockerfile for Next.js static export with nginx - nginx.conf with proper SPA routing (try_files fallback) - docker-compose.yml with Traefik labels for post-appitalism.app 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
4d47acf5c3
commit
501ef48e53
|
|
@ -0,0 +1,34 @@
|
|||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the static export
|
||||
RUN pnpm build
|
||||
|
||||
# Production stage - nginx to serve static files
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy custom nginx config for SPA routing
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy the static export from builder
|
||||
# Next.js static export outputs to 'out' folder
|
||||
COPY --from=builder /app/out /usr/share/nginx/html
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
services:
|
||||
post-app-prod:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
# Main domain
|
||||
- "traefik.http.routers.post-app.rule=Host(`post-appitalism.app`) || Host(`www.post-appitalism.app`)"
|
||||
- "traefik.http.routers.post-app.entrypoints=web"
|
||||
- "traefik.http.services.post-app.loadbalancer.server.port=80"
|
||||
# Redirect www to non-www
|
||||
- "traefik.http.middlewares.post-app-redirect.redirectregex.regex=^https?://www\\.post-appitalism\\.app/(.*)"
|
||||
- "traefik.http.middlewares.post-app-redirect.redirectregex.replacement=https://post-appitalism.app/$${1}"
|
||||
- "traefik.http.middlewares.post-app-redirect.redirectregex.permanent=true"
|
||||
networks:
|
||||
- traefik-public
|
||||
|
||||
networks:
|
||||
traefik-public:
|
||||
external: true
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Enable gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied any;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Handle Next.js static export routes
|
||||
location / {
|
||||
# Try exact file, then .html extension, then directory, then fallback to index.html
|
||||
try_files $uri $uri.html $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location /_next/static/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
}
|
||||
|
||||
# Cache other static files
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, max-age=31536000";
|
||||
}
|
||||
|
||||
# Custom error pages
|
||||
error_page 404 /404.html;
|
||||
error_page 500 502 503 504 /500.html;
|
||||
}
|
||||
Loading…
Reference in New Issue