-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnginx.conf
More file actions
73 lines (62 loc) · 2.19 KB
/
nginx.conf
File metadata and controls
73 lines (62 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# nginx.conf - Load balancer for scaled Netskrafl deployment
#
# Usage with docker-compose:
# 1. Uncomment the nginx service in docker-compose.yml
# 2. Change app service to use 'expose' instead of 'ports'
# 3. Run: docker-compose --profile scaled up --scale app=3
#
# This will run 3 app instances behind nginx on port 80.
events {
worker_connections 1024;
}
http {
# Upstream backend pool
# Docker's internal DNS resolves 'app' to all container IPs
upstream backend {
server app:8080;
# Keepalive connections to backend for better performance
keepalive 32;
}
# Logging format
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'upstream=$upstream_addr response_time=$upstream_response_time';
access_log /dev/stdout main;
error_log /dev/stderr warn;
server {
listen 80;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
# Proxy settings
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection ""; # Enable keepalive
# Timeouts
proxy_connect_timeout 10s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
# Main application
location / {
proxy_pass http://backend;
}
# Health check endpoint for the load balancer itself
location /nginx-health {
access_log off;
return 200 'OK\n';
add_header Content-Type text/plain;
}
# Static files with caching (optional optimization)
# Uncomment if you want nginx to serve static files directly
# location /static/ {
# alias /app/static/;
# expires 1d;
# add_header Cache-Control "public, immutable";
# }
}
}