需要注意两个地方:
alias /www/wwwroot/A/: //指定目灵
try_files $uri $uri/ /a/index.html; // 找不到文件时转发到index.html
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 20m;
#gzip on;
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
# 前端A
location /A {
root html/testA/;
index index.html;
try_files $uri $uri/ /a/index.html;
}
# 前端B
location /B {
alias html/testB/;
index index.html;
try_files $uri $uri/ /a/index.html;
}
# 后端
location /api {
proxy_pass http://127.0.0.1:9092/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Origin $http_origin;
}
}
}