为了账号安全,请及时绑定邮箱和手机立即绑定

关于nginx使用路径重定向至服务的问题?

关于nginx使用路径重定向至服务的问题?

慕田峪4524236 2018-06-13 13:01:02
现在有域名www.services.com, 对应的服务器上部署了三个服务ServiceA, ServiceB, ServiceC,每个服务的访问方法为访问对应路径的index.html文件即可, 如ServiceA服务的前端路径为Path/to/A, ServiceB服务的前端路径为pATh/tO/B然后我想要实现通过http://www.services.com/ServiceA 来访问Path/to/A/index.html, 于是我尝试了这样子的配置:http {  listen 80;  server_name www.services.com;  # nginx默认配置   location /  {    root html;    index index.html index.htm   }  # ServiceA配置   locaton ^~ /ServiceA {    root Path/to/A     index.index.html index.htm   } }而最后实际上会请求访问到/Path/to/A/ServiceA/或是/usr/share/nginx/html/ServiceA/, 于是返回404报错.请问为什么会出现这样的路由规则? 如何实现期望效果?
查看完整描述

2 回答

?
HUH函数

TA贡献1836条经验 获得超4个赞

可以使用 try files 解决

# ServiceA配置 locaton ^~ /ServiceA { 
    root Path/to/A ;    #index.index.html index.htm 
    try_files $url  index.html;
}


查看完整回答
反对 回复 2018-07-21
?
慕森王

TA贡献1777条经验 获得超3个赞

index index.html index.htm;  locaton /ServiceA/ {    alias Path/to/A/;
  }  locaton /ServiceB/ {    alias Path/to/B/;
  }  locaton /ServiceC/ {    alias Path/to/C/;
  }


查看完整回答
反对 回复 2018-07-21
  • 2 回答
  • 0 关注
  • 1289 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信