如何解决uri后使用位置块重定向的nginx重定向问题
这是我当前的默认值。
server {
listen 80;
listen [::]:80;
server_name _;
location /bar {
rewrite ^/(.*)$ https://objectstorage.ca-city.oraclecloud.com/n/randomhash/b/bucketname/o/$1 permanent;
## i also tried rewrite ^/bar/(.*)$ https://objectstorage.ca-city.oraclecloud.com/n/randomhash/b/bucketname/o/$1 permanent;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
如果我使用http://ip_address/bar/file.txt,我想要的是它应该转到https://objectstorage.ca-city.oraclecloud.com/n/randomhash/b/bucketname/o/file.txt
我得到的最接近的是在位置使用^ /(。*)$并将其从http:// ip_address / bar路由到ttps://objectstorage.ca-city.oraclecloud.com/n/randomhash/ b / bucketname / o / bar,它没有看到/file.txt,当我尝试^ / bar /(.*)$时,它会直接跳至404页面。
请注意,我使用的是traefik入口,并且有一个入口看着/ bar,并将其路由到nginx容器。
提前谢谢
编辑: 我现在通过修复traefik入口使其工作,因为它仅与/ bar匹配。而不是使用使用match的ingressroute,我将ingress和path用作/ bar并使用以下方法:
paths:
- backend:
serviceName: my-nginx
servicePort: 80
path: /bar
location ~* /bar {
rewrite ^/bar/(.*) https://objectstorage.ca-city.oraclecloud.com/n/randomhash/b/bucketname/o/$1 permanent
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。