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

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

Nginx configuration proxy, access returns 301?

问题

以下是nginx配置的中文翻译:

这是nginx的配置:

  1. location /debug {
  2. proxy_pass http://127.0.0.1:32339/;
  3. proxy_set_header Host $http_host;
  4. }

期望的访问 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 仍然存在

  1. location /debug {
  2. proxy_pass http://127.0.0.1:32339;
  3. proxy_set_header Host $http_host;
  4. }

nginx 版本 1.23.3

请帮助我,谢谢;

我之前尝试过这个配置,但结果仍然相同

  1. location /debug/ {
  2. proxy_pass http://127.0.0.1:32339;
  3. rewrite /debug/(.*) /$1 break;
  4. }

使用curl执行的结果

  1. [root@node1 conf.d]# curl --location http://127.0.0.1:80/debug/a/b
  2. <html>
  3. <head><title>404 Not Found</title></head>
  4. <body>
  5. <center><h1>404 Not Found</h1></center>
  6. <hr><center>nginx/1.23.3</center>
  7. </body>
  8. </html>
  9. [root@node1 conf.d]#
英文:

This is the nginx configuration:

  1. location /debug {
  2. proxy_pass http://127.0.0.1:32339/;
  3. proxy_set_header Host $http_host;
  4. }

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

  1. location /debug {
  2. proxy_pass http://127.0.0.1:32339;
  3. proxy_set_header Host $http_host;
  4. }

nginx version 1.23.3

Please help me, thanks;

I have tried this configuration before, but the result is still the same

  1. location /debug/ {
  2. proxy_pass http://127.0.0.1:32339;
  3. rewrite /debug/(.*) /$1 break;
  4. }

Using curl to execute results

  1. [root@node1 conf.d]# curl --location http://127.0.0.1:80/debug/a/b
  2. <html>
  3. <head><title>404 Not Found</title></head>
  4. <body>
  5. <center><h1>404 Not Found</h1></center>
  6. <hr><center>nginx/1.23.3</center>
  7. </body>
  8. </html>
  9. [root@node1 conf.d]#

答案1

得分: 0

你试过这个吗?

  1. location ~ ^/debug(.*) {
  2. proxy_pass http://127.0.0.1:32339$1;
  3. proxy_set_header Host $http_host;
  4. }
英文:

Have you tried this?

  1. location ~ ^/debug(.*) {
  2. proxy_pass http://127.0.0.1:32339$1;
  3. proxy_set_header Host $http_host;
  4. }

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:

确定