44 lines
1.5 KiB
Plaintext
44 lines
1.5 KiB
Plaintext
# 该模板会由容器启动时自动生成配置并渲染变量 ${BACKEND_HOST} ${BACKEND_PORT}
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# 开启压缩,减小传输体积
|
|
gzip on;
|
|
gzip_min_length 1k;
|
|
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
|
|
|
|
client_max_body_size 20m;
|
|
|
|
# 单页应用(SPA)history 路由:找不到对应文件时回退到 index.html
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# 静态资源加缓存
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|ttf)$ {
|
|
expires 7d;
|
|
access_log off;
|
|
}
|
|
|
|
# 反向代理后端接口(覆盖本项目后端的所有路由前缀)
|
|
# 使用变量形式,后端容器没启动时 nginx 也能正常启动,只是请求会返回 502
|
|
location ~ ^/(api|advisors|c_lass|docs|redoc|openapi\.json) {
|
|
resolver 127.0.0.11 valid=30s; # Docker 内嵌 DNS
|
|
set $ss_backend http://${BACKEND_HOST}:${BACKEND_PORT};
|
|
proxy_pass $ss_backend; # 变量形式必须省略 URI 部分,原始请求路径会原样透传
|
|
|
|
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;
|
|
}
|
|
|
|
access_log /var/log/nginx/frontend_access.log;
|
|
error_log /var/log/nginx/frontend_error.log;
|
|
}
|