我遇到了一个非常奇怪的问题。我正在尝试使用 nginx 将 gerrit 包装在 SSL/HTTPS 中,并且只有当我让 dev.company.com/指向 gerrit 时它才有效(我更喜欢 dev.company.com/gerrit/因为 Web 服务器也应该托管其他服务。)
这是我能找到的唯一可行的解决方案。
gerrit 的 etc/gerrit.config:
[gerrit]
canonicalWebUrl = https://dev.company.com/
[httpd]
listenUrl = proxy-https://127.0.0.1:8081/
(snip)
nginx在sites-available中的配置:
server {
listen 443 ssl;
server_name dev.company.com;
ssl on;
(ssl certificates blah blah)
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
如果我更改为以下内容:
gerrit.config:
[gerrit]
canonicalWebUrl = https://dev.company.com/gerrit/
[httpd]
listenUrl = proxy-https://127.0.0.1:8081/
(snip)
nginx 配置:
server {
listen 443 ssl;
server_name dev.company.com;
ssl on;
(ssl certificates blah blah)
location /gerrit/ {
proxy_pass http://127.0.0.1:8081/;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
(请注意 proxy_pass 上的尾部斜杠。)
除了带有转义字符的请求(例如 %2F,gerrit 有很多这样的字符)之外,一切都可以工作。因此,gerrit 作为一个站点,只能工作一半。
我觉得this answer应该引导正确的方向,但我就是无法让事情发挥作用。
编辑:我认为this讨论遇到了同样的错误。
最佳答案
您链接的最后一个讨论,https://groups.google.com/forum/#!topic/repo-discuss/iSHHa4krRLo ,实际上确实包含一个分辨率:
However, for the record, I give a try to nginx with a proxy_pass directive without /gerrit and it worked.
这是因为您不应在 proxy_pass
中使用尾部斜杠或任何其他路径规范,按照 https://stackoverflow.com/a/49702013 ,您和他们都引用,以避免路径被标准化和解码。
gerrit.config:
[gerrit]
canonicalWebUrl = https://dev.example.com/gerrit/
[httpd]
listenUrl = proxy-https://127.0.0.1:8081/gerrit/
nginx.conf:
server {
listen 443;
server_name dev.example.com;
ssl on;
ssl_certificate conf/server.crt;
ssl_certificate_key conf/server.key;
location ^~ /gerrit/ {
proxy_pass http://127.0.0.1:8081;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
这整件事真的是直接出自 https://gerrit-review.googlesource.com/Documentation/config-reverseproxy.html ,说实话。
看起来尾随 /gerrit/
在httpd.listenUrl
,并且缺少尾随 /
在proxy_pass
,是您需要对配置进行的更改才能正常工作。
确实,您在解码转义字符时遇到的问题在 https://stackoverflow.com/a/49702013 中有描述。 ,这正是由于 proxy_pass
中的尾部斜杠造成的您在没有充分理由的情况下使用。
关于ssl - nginx 代理的 gerrit 仅在顶级目录上为 "hosted"时才有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56790597/