worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# ===================== Gzip 压缩配置 START ====================
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_static on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/javascript application/xml application/xml+rss font/ttf font/otf image/svg+xml;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
# ===================== Gzip 压缩配置 END =====================
server {
# 监听端口
listen 0000;
server_name localhost;
port_in_redirect off;
# 全局添加的缓存选项
add_header Cache-Control no-cache;
# =============== 主应用路径 产物转发规则 START ==============
location / {
# 访问根路径时重定向到正式环境
rewrite ^/$ /prod/ permanent;
}
location /test {
try_files $uri $uri/ /main-app/test/index.html last;
}
location /prod {
try_files $uri $uri/ /main-app/prod/index.html last;
}
location /demo {
try_files $uri $uri/ /main-app/demo/index.html last;
}
location /trial {
try_files $uri $uri/ /main-app/trial/index.html last;
}
# =============== 主应用路径 产物转发规则 END ===============
# =============== 子应用路径 产物转发规则 START =============
location ~ ^/sub-app/([^/]+)/$ {
# 没指定就转发到prod环境
rewrite ^/sub-app/([^/]+)/$ /sub-app/$1/prod/ permanent;
}
location ~ ^/sub-app/([^/]+)/(.+)$ {
# 若指定了,例如/sub-app/some-app/test,则不进行重定向,直接访问指定目录
}
# =============== 子应用路径 产物转发规则 END ===============
# =============== 主应用&系统管理 接口转发 START ============
location /api {
# 原来的api就转发到正式环境prod-api
rewrite ^/api/(.*)$ /prod-api/$1 permanent;
}
location /test-api {
proxy_pass http://127.0.0.1:0000;
}
location /prod-api {
proxy_pass http://127.0.0.1:0000;
}
location /demo-api {
proxy_pass http://127.0.0.1:0000;
}
location /trial-api {
proxy_pass http://127.0.0.1:0000;
}
# =============== 主应用&系统管理 接口转发 END =============
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html/main;
}
}
}