如何在不以斜杠结尾的情况下路由特定的uri端点



我的当前设置:

  1. 用户输入www.example.com/example/xx/healthcheck
  2. kubernetes traefik ingress以后端为例,并转到nginx服务
  3. nginx的这种小配置:
server {
listen       80;
listen  [::]:80;
server_name  localhost;

location /example/xx/healthcheck {
root  /usr/share/nginx/html;
index output.html;
}

我把output.html放在/usr/share/nginx/html/example/xx/healthcheck 中

我的问题是,当我点击www.example.com/example/xx/healthcheck时,它不会加载页面。它只有在末尾有斜杠时才有效www.example.com/example/xx/healthcheck/

有合适的更好的方法吗?我想要www.example.com/example/xx/healthcheck,它就会出现在页面上。

谢谢

您可以使用

location = /example/xx/healthcheck {
default_type text/html;
alias /any/path/to/output.html;
}

小心-斜杠结束的请求www.example.com/example/xx/healthcheck/将不再使用此配置,尽管如果您使用location /example/xx/healthcheck { ... }作为第二个请求或使用类似的重写规则,它会起作用

rewrite ^/example/xx/healthcheck/$ /example/xx/healthcheck;

相关内容

最新更新