-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample-nginx.conf
More file actions
91 lines (74 loc) · 2.8 KB
/
Copy pathsample-nginx.conf
File metadata and controls
91 lines (74 loc) · 2.8 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
worker_processes auto;
events {
worker_connections 1024;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
# Log configuration
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# Define log format with more details
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time $upstream_response_time';
# Use detailed log format
access_log /var/log/nginx/access.log main;
# Optimized settings for reverse proxy
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
client_max_body_size 10m;
server_tokens off;
# Gzip compression for frontend assets
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss image/svg+xml;
# Proxy cache settings
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=api_cache:10m max_size=100m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
# Proxy headers settings
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;
# Main server block
server {
listen 80;
server_name localhost;
# Root directory for frontend assets
root /var/www;
# Serve frontend static files
location / {
try_files $uri $uri/ /index.html;
expires 1d;
add_header Cache-Control "public, max-age=86400";
}
# API proxy configuration
location /api/ {
proxy_pass http://backend-api:8080/;
proxy_cache api_cache;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
# Don't cache POST/PUT/DELETE requests
proxy_cache_methods GET HEAD;
# Add cache status header
add_header X-Cache-Status $upstream_cache_status;
# Enable detailed logging for API requests
access_log /var/log/nginx/api-access.log main;
}
# 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;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
}
}