File tree Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ # ---------- Builder stage ----------
2+ FROM node:20-slim AS builder
3+
4+ # Set working directory
5+ WORKDIR /usr/src/app
6+
7+ # Copy package files to the container
8+ COPY package*.json ./
9+
10+ # Install the dependencies and build
11+ RUN npm cache clean --force \
12+ && npm ci
13+
14+ # Copy source code
15+ COPY . .
16+
17+ # Build the application
18+ RUN npm run build:prod
19+
20+
21+ # ---------- Production stage ----------
22+ FROM nginx:alpine
23+
24+ # Copy built assets from builder stage
25+ COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
26+
27+ COPY nginx.conf /etc/nginx/nginx.conf
28+
29+ # Prepare directories with correct ownership for nginx user
30+ RUN mkdir -p /var/cache/nginx/client_temp /var/run && \
31+ chown -R 65532:65532 /var/cache/nginx /var/run
32+
33+ # Switch to non-root user
34+ USER 65532:65532
35+
36+ # Expose port
37+ EXPOSE 8080
38+
39+ # Set environment variables
40+ ENV PORT=8080
41+
42+ # Start the production server
43+ CMD ["nginx" , "-g" , "daemon off;" ]
Original file line number Diff line number Diff line change 1+
2+ worker_processes 1;
3+
4+ error_log /var/log/nginx/error.log warn;
5+ pid /tmp/nginx.pid ;
6+
7+ events {
8+ worker_connections 1024 ;
9+ }
10+
11+ http {
12+ log_format main '$remote_addr - $remote_user [$time_local] - $http_x_api_version - "$request" '
13+ '$status $body_bytes_sent "$http_referer" '
14+ '"$http_user_agent" "$http_x_forwarded_for"' ;
15+
16+ access_log /var/log/nginx/access.log main;
17+
18+ include /etc/nginx/mime.types ;
19+ default_type application/octet-stream ;
20+
21+
22+ # --- Additions for Gzip Compression ---
23+ gzip on;
24+ gzip_types text/plain text/html text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
25+ gzip_comp_level 5;
26+ gzip_min_length 1000 ;
27+ gzip_proxied any;
28+ gzip_vary on;
29+ gzip_disable "msie6" ;
30+ # --- End Gzip Additions ---
31+
32+ server {
33+ listen 8080 ;
34+
35+ location / {
36+ root /usr/share/nginx/html;
37+ index index .html;
38+ try_files $uri $uri / /index .html;
39+ }
40+
41+ # Static assets (cache enabled)
42+ location ~ * \.(css|js|gif|jpeg|jpg|png|ico|woff|woff2|ttf|otf|svg|eot)$ {
43+ root /usr/share/nginx/html;
44+ expires 30d ;
45+ add_header Cache-Control "public, no-transform" ;
46+ try_files $uri =404 ;
47+ }
48+
49+ # Backend API
50+ location /api/ {
51+ proxy_pass http ://host.docker.internal :4000 ;
52+ proxy_http_version 1.1;
53+ proxy_set_header Host $host ;
54+ proxy_set_header X-Real-IP $remote_addr ;
55+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
56+ proxy_set_header X-Forwarded-Proto $scheme ;
57+ }
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments