nginx proxy_pass 与 uri 不工作

nginx proxy_pass 与 uri 不工作

以下代理可以优雅地解析http://my.org/代理地址:

location / {
  proxy_pass http://127.0.0.1:8082;
}

但是,在 URI 中添加名称会破坏一切并导致 404 错误:

location /luigi/ {
  proxy_pass http://127.0.0.1:8082;
}

也尝试过重写但无济于事:

location /luigi/ {
  rewrite ^/luigi/(.*)$ /$1 break;
  proxy_pass http://127.0.0.1:8082;
}

accesss.log

myip - - [24/Jul/2020:16:56:36 -0400] "GET /luigi/ HTTP/1.1" 404 513 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"
myip - - [24/Jul/2020:16:56:36 -0400] "GET /error?src=404&ifr=1&error= HTTP/1.1" 404 153 "http://myurl/luigi/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"
myip - - [24/Jul/2020:16:56:47 -0400] "GET /luigi/ HTTP/1.1" 404 513 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"
myip - - [24/Jul/2020:16:56:47 -0400] "GET /error?src=404&ifr=1&error= HTTP/1.1" 404 153 "http://myurl/luigi/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"

error.log

2020/07/24 16:56:32 [notice] 107788#0: signal process started
2020/07/24 16:56:36 [error] 107789#0: *13 open() "/usr/share/nginx/html/error" failed (2: No such file or directory), client: myip, server: , request: "GET /error?src=404&ifr=1&error= HTTP/1.1", host: "myurl", referrer: "http://myurl/luigi/"
2020/07/24 16:56:47 [error] 107789#0: *13 open() "/usr/share/nginx/html/error" failed (2: No such file or directory), client: myip, server: , request: "GET /error?src=404&ifr=1&error= HTTP/1.1", host: "myurl", referrer: "http://myurl/luigi/"

有人可以帮忙吗?

答案1

您可以尝试以下操作:

location ~ /luigi/(.*) {
    proxy_pass http://127.0.0.1:8082/$1;
}

/luigi这将捕获变量后的路径,并将该路径添加到proxy_pass路径。

您需要确保您的应用程序在其创建的链接中生成正确的 URL。通常,应用程序会生成如下 URL,http://127.0.0.1:8082而无法在反向代理配置中将其设置为生成正确的 URL,这是一个问题。

相关内容