【问题标题】:Nexus3 + Nginx Reverse proxyNexus3 + Nginx 反向代理
【发布时间】:2019-03-19 19:30:20
【问题描述】:

我正在尝试让 Ne​​xus3 在 Nginx 后面运行。

Nginx 用作反向代理和 SSL 终止。通过 Nginx 访问 /nexus 路径时,出现多个错误,例如“操作失败,无法访问服务器”和“无法检测到您连接到哪个节点”。在不通过 Nginx 的情况下访问 Nexus UI 效果很好,这让我认为错误出在 Nginx 上。

NginX 配置文件

location /nexus {
            proxy_pass http://localhost:8081/nexus/;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            resolver 8.8.8.8 8.8.4.4 ipv6=off;
    }

【问题讨论】:

  • 不通过Nginx访问Nexus UI时,URI是否包含/nexus/前缀?
  • 它无需通过 Nginx 即可工作,即访问 localhost:8081/nexus 上的 URL。 URI 确实包含上下文路径 /nexus/ 我正在使用 Nginx 进行 SSL 终止。
  • 尝试:proxy_pass http://localhost:8081/nexus;(没有跟踪 /)以匹配 location 值。另外,请尝试删除 Host 标头语句。
  • 感谢理查德,解决了这个问题。请添加为答案,以便我将其标记为已解决。

标签: nginx reverse-proxy nexus3


【解决方案1】:

如果您使用http://localhost:8081/nexus 访问该服务,它可以工作。

您当前的配置是使用proxy_pass 将URI /nexus 更改为/nexus/。通常,建议在 locationproxy_pass URI 或两者都不使用尾随 /

例如:

location /nexus {
    proxy_pass http://localhost:8081/nexus;
    ...
}

事实上,您根本不需要修改 URI,因此您可以将其从 proxy_pass 指令中完全删除。

以下应该是等效的,但更有效:

location /nexus {
    proxy_pass http://localhost:8081;
    ...
}

默认情况下,Host 标头设置为proxy_pass 指令的值(即locatlhost:8081),已知该指令可以正常工作。您可能会发现您的声明proxy_set_header Host $host:$server_port; 是不必要的。

详情请见this document

【讨论】:

  • 我发现,在 Nexus OSS 3.15.2-01 上,省略 Host 标头会导致 400 Bad Request。我让 nginx 在 8888 上侦听代理到 8081 的 nexus。
  • 你是救生员!!!在 proxy_pass 的所有 nginx 示例中,始终严格建议包含斜杠!但是天知道为什么这对 Nexus 不起作用,但建议的有效选项非常有效!谢谢!
  • 我花了好几个小时才找到你的答案。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-05
  • 2011-08-09
  • 2013-02-18
  • 2021-04-08
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多