server {
listen 80;
server_name localhost;
# 10001是前端,访问 http://localhost:80/ 时,转发到http://localhost:10001/
location / {
proxy_pass http://localhost:10001/;
}
# 10000是网关,访问 http://localhost:80/gateway/ 时,转发到http://localhost:10000/
location /gateway/ {
proxy_pass http://localhost:10000/;
}
}
核心思想:
多个转发共用一个schema、host和port,即可满足浏览器同源策略,即可跨域