|
| 1 | +worker_processes auto; |
| 2 | + |
| 3 | +error_log /dev/stderr warn; |
| 4 | +pid /tmp/nginx.pid; |
| 5 | + |
| 6 | +events { |
| 7 | + worker_connections 1024; |
| 8 | +} |
| 9 | + |
| 10 | +http { |
| 11 | + log_format main '$remote_addr - $remote_user [$time_local] - $http_x_api_version - "$request" ' |
| 12 | + '$status $body_bytes_sent "$http_referer" ' |
| 13 | + '"$http_user_agent" "$http_x_forwarded_for"'; |
| 14 | + |
| 15 | + access_log /dev/stdout main; |
| 16 | + |
| 17 | + include /etc/nginx/mime.types; |
| 18 | + default_type application/octet-stream; |
| 19 | + |
| 20 | + # Temporary file paths for non-root user |
| 21 | + client_body_temp_path /var/cache/nginx/client_temp; |
| 22 | + proxy_temp_path /var/cache/nginx/proxy_temp; |
| 23 | + fastcgi_temp_path /var/cache/nginx/fastcgi_temp; |
| 24 | + uwsgi_temp_path /var/cache/nginx/uwsgi_temp; |
| 25 | + scgi_temp_path /var/cache/nginx/scgi_temp; |
| 26 | + |
| 27 | + # Security headers |
| 28 | + add_header X-Frame-Options "SAMEORIGIN" always; |
| 29 | + add_header X-XSS-Protection "1; mode=block" always; |
| 30 | + add_header X-Content-Type-Options "nosniff" always; |
| 31 | + add_header Referrer-Policy "no-referrer-when-downgrade" always; |
| 32 | + add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; |
| 33 | + |
| 34 | + # Gzip Compression |
| 35 | + gzip on; |
| 36 | + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; |
| 37 | + gzip_comp_level 5; |
| 38 | + gzip_min_length 1000; |
| 39 | + gzip_proxied any; |
| 40 | + gzip_vary on; |
| 41 | + gzip_disable "msie6"; |
| 42 | + |
| 43 | + # Upstream backend configuration |
| 44 | + upstream backend { |
| 45 | + server ${BACKEND_SERVICE}; |
| 46 | + } |
| 47 | + |
| 48 | + server { |
| 49 | + listen 8080; |
| 50 | + |
| 51 | + # Health check endpoint |
| 52 | + location /health { |
| 53 | + access_log off; |
| 54 | + return 200 'healthy\n'; |
| 55 | + } |
| 56 | + |
| 57 | + location / { |
| 58 | + root /usr/share/nginx/html; |
| 59 | + index index.html; |
| 60 | + try_files $uri $uri/ /index.html; |
| 61 | + } |
| 62 | + |
| 63 | + # Static assets (cache enabled) |
| 64 | + location ~* \.(css|js|gif|jpeg|jpg|png|ico|woff|woff2|ttf|otf|svg|eot)$ { |
| 65 | + root /usr/share/nginx/html; |
| 66 | + expires 30d; |
| 67 | + add_header Cache-Control "public, no-transform"; |
| 68 | + try_files $uri =404; |
| 69 | + } |
| 70 | + |
| 71 | + # Backend API |
| 72 | + location /api/ { |
| 73 | + proxy_pass http://backend/api/; |
| 74 | + proxy_http_version 1.1; |
| 75 | + proxy_set_header Host $host; |
| 76 | + proxy_set_header X-Real-IP $remote_addr; |
| 77 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 78 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 79 | + |
| 80 | + # Timeouts |
| 81 | + proxy_connect_timeout 60s; |
| 82 | + proxy_send_timeout 60s; |
| 83 | + proxy_read_timeout 60s; |
| 84 | + |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments