Nginx配置代理,访问返回301?

huangapple go评论49阅读模式
英文:

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 的代理
Nginx配置代理,访问返回301?

配置 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
Nginx配置代理,访问返回301?

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;
  }

huangapple
  • 本文由 发表于 2023年4月6日 19:57:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定