79 lines
2.2 KiB
Nginx Configuration File
79 lines
2.2 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name _;
|
|
|
|
# Use Docker embedded DNS so upstream names can resolve at request time
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_comp_level 6;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/javascript
|
|
application/xml+rss
|
|
application/json
|
|
image/svg+xml;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options DENY;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin";
|
|
|
|
# Handle Vue Router history mode
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Cache static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
access_log off;
|
|
}
|
|
|
|
# API proxy to backend (container network)
|
|
location /api/ {
|
|
# Defer DNS resolution to avoid startup failure when backend name not yet resolvable
|
|
set $backend_upstream http://backend:18888;
|
|
proxy_pass $backend_upstream;
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# 添加 CORS 头支持
|
|
proxy_pass_header Access-Control-Allow-Origin;
|
|
proxy_pass_header Access-Control-Allow-Methods;
|
|
proxy_pass_header Access-Control-Allow-Headers;
|
|
proxy_pass_header Access-Control-Allow-Credentials;
|
|
|
|
# 添加日志用于调试
|
|
access_log /var/log/nginx/api_proxy.log;
|
|
error_log /var/log/nginx/api_proxy_error.log;
|
|
}
|
|
|
|
# Disable access to hidden files
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# Custom error pages
|
|
error_page 404 /index.html;
|
|
error_page 500 502 503 504 /index.html;
|
|
} |