我设置了一些 Apache mod_rewrite 规则来将 Maven 部署从一个 url/服务器重定向到另一个。我们正在从 Nexus 迁移到 Artifactory,需要设置这些重定向,以便团队仍然可以在一段时间内使用 Nexus URL 而不会破坏构建。这是我们的 mod_rewrite 规则的示例:
RewriteRule ^/nexus/content/repositories/nexus-repository/(.*)$ https://artifactory-instance.net/repository/$1 [NE,R=301,L]
该规则成功地将 GET 请求重定向到新的 Artifactory URL,但我们遇到了授权标头在重定向中被丢弃的问题。我们收到 401 错误,通过运行 cURL PUT 命令来推送单个工件,我可以看到授权标头正在被删除:
...
> PUT /nexus/content/repositories/nexus-repository/com/maven/hello-world/1.0.0/hello-world-1.0.0.jar HTTP/1.1
> Host: nexus-instance.com
> Authorization: Basic XXXXXXXXXX
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 2540
> Expect: 100-continue
>
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 23 Apr 2020 17:27:22 GMT
< Server: Apache/2.4.37 (Red Hat Enterprise Linux)
< Location: https://artifactory-instance.net/repository/com/maven/hello-world/1.0.0/hello-world-1.0.0.jar
< Content-Length: 311
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
...
> PUT /repository/com/maven/hello-world/1.0.0/hello-world-1.0.0.jar HTTP/1.1
> Host: artifactory-instance.net
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 2540
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 401 Unauthorized
< Date: Thu, 23 Apr 2020 17:27:22 GMT
...
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="Artifactory Realm"
< Content-Type: application/json;charset=ISO-8859-1
< Transfer-Encoding: chunked
...
cURL 有一个名为--location-trusted
. 当我将它应用到我的测试 cURL 命令时,它会将授权标头传递给重定向。
--location-trusted
我的问题是,在 httpd中是否有任何等价物?我该怎么做才能通过重定向传递身份验证标头?
我想出了我需要什么才能让它工作。mod_rewrite 不会让它工作,但使用 mod_proxy 我能够让它工作:
它不会将用户重定向到 URL,但会在链接 URL 中显示 Artifactory 内容。