英文:
Nginx configuration proxy, access returns 301?
问题
以下是nginx配置的中文翻译:
这是nginx的配置:
location /debug {
proxy_pass http://127.0.0.1:32339/;
proxy_set_header Host $http_host;
}
期望的访问 http://127.0.0.1:80/debug/a/b 代理到 http://127.0.0.1:32339/a/b
实际服务器返回 301 重定向到 http://127.0.0.1:80/a/b。
我不希望它这样做,它应该充当 http://127.0.0.1:32339/a/b 的代理
配置 proxy_pass http://127.0.0.1:32339/;
移除末尾的斜杠,它将不再重定向,但 /debug
仍然存在
location /debug {
proxy_pass http://127.0.0.1:32339;
proxy_set_header Host $http_host;
}
nginx 版本 1.23.3
请帮助我,谢谢;
我之前尝试过这个配置,但结果仍然相同
location /debug/ {
proxy_pass http://127.0.0.1:32339;
rewrite /debug/(.*) /$1 break;
}
使用curl执行的结果
[root@node1 conf.d]# curl --location http://127.0.0.1:80/debug/a/b
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.23.3</center>
</body>
</html>
[root@node1 conf.d]#
英文:
This is the nginx configuration:
location /debug {
proxy_pass http://127.0.0.1:32339/;
proxy_set_header Host $http_host;
}
Expected visits http://127.0.0.1:80/debug/a/b Proxy to http://127.0.0.1:32339/a/b
The actual server returned 301 redirects to http://127.0.0.1:80/a/b.
I don't want him to do this, it should act as an agent http://127.0.0.1:32339/a/b
Configure proxy_ pass http://127.0.0.1:32339/;
Remove the end, it will no longer redirect, but /debug
still exists
location /debug {
proxy_pass http://127.0.0.1:32339;
proxy_set_header Host $http_host;
}
nginx version 1.23.3
Please help me, thanks;
I have tried this configuration before, but the result is still the same
location /debug/ {
proxy_pass http://127.0.0.1:32339;
rewrite /debug/(.*) /$1 break;
}
Using curl to execute results
[root@node1 conf.d]# curl --location http://127.0.0.1:80/debug/a/b
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.23.3</center>
</body>
</html>
[root@node1 conf.d]#
答案1
得分: 0
你试过这个吗?
location ~ ^/debug(.*) {
proxy_pass http://127.0.0.1:32339$1;
proxy_set_header Host $http_host;
}
英文:
Have you tried this?
location ~ ^/debug(.*) {
proxy_pass http://127.0.0.1:32339$1;
proxy_set_header Host $http_host;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论