如何解决nginx-如何路由特定的uri端点而不以斜杠结尾
我当前的设置:
- 用户输入www.example.com/example/xx/healthcheck
- 使用后端作为/ example的kubernetes traefik入口并进入nginx服务
- 具有这种小配置的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;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。