maven - 如何配置 maven settings.xml 以访问 apache 代理背后的 nexus

标签 maven nexus mod-proxy http-proxy

我在从 nexus 获取 Artifact 时遇到了麻烦,我希望社区可以帮助我。在 nexus Web 应用程序中访问和工作不是问题(我已将基本 URL 设置为 https://www.fakesitename.com/nexus )。

所有调用 https://www.fakesitename.com/nexus被重定向/转发/代理(正确的术语是什么?)到网络上的内部服务器

<VirtualHost *:443>
  ServerName www.fakesitename.com
  ServerAdmin webmaster@mysite.com

  DocumentRoot /var/www
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  <Proxy *>
    AddDefaultCharset Off
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyRequests Off
  ProxyPreserveHost On

  ProxyPass /nexus http://192.168.0.178:8081/nexus
  ProxyPassReverse /nexus http://192.168.0.178:8081/nexus

  SSLEngine on
  SSLCertificateFile /certs/mysite/ssl.crt
  SSLCertificateKeyFile /certs/mysite/ssl.key
</VirtualHost>

settings.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
          http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>public</id>
      <mirrorOf>*</mirrorOf>
      <url>https://www.fakesitename.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

<!-- What should be in here?
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>www.fakesitename.com</host>
      <port>443</port>
      <nonProxyHosts>127.0.0.1|192.168.0.178</nonProxyHosts>
    </proxy>
  </proxies>
-->
  <servers>
    <server>
      <id>releases</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://www.fakesitename.com/nexus/content/groups/public</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>https://www.fakesitename.com/nexus/content/groups/public</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

例如,当我运行 mvn clean of a project with the proxies section outcommented 我得到...peer not authentication ...
 [INFO] Scanning for projects...
 Downloading: https://www.fakesitename.com/nexus/content/groups/public/com/fakesitename/poms/super/1.3/super-1.3.pom
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.fakesitename.library:application:1.3-SNAPSHOT (/tmp/application/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not transfer artifact com.fakesitename.poms:super:pom:1.3 from/to public (https://www.fakesitename.com/nexus/content/groups/public): peer not authenticated and 'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

j

并且该部分未注释
[INFO] Scanning for projects...
Downloading: https://www.fakesitename.com/nexus/content/groups/public/com/fakesitename/poms/super/1.3/super-1.3.pom
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (org.apache.maven.wagon.providers.http.httpclient.NoHttpResponseException) caught when connecting to the target host: The target server failed to respond
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (org.apache.maven.wagon.providers.http.httpclient.NoHttpResponseException) caught when connecting to the target host: The target server failed to respond
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (org.apache.maven.wagon.providers.http.httpclient.NoHttpResponseException) caught when connecting to the target host: The target server failed to respond
mar 24, 2013 10:12:39 EM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.fakesitename.library:application:1.3-SNAPSHOT (/tmp/application/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not transfer artifact com.fakesitename.poms:super:pom:1.3 from/to public (https://www.fakesitename.com/nexus/content/groups/public): The target server failed to respond and 'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

如果我更改要使用的设置文件
http://192.168.0.178:8081直接就成功了。
[INFO] Scanning for projects...
Downloading: http://192.168.0.178:8081/nexus/content/groups/public/com/fakesitename/poms/super/1.3/super-1.3.pom
Downloaded: http://192.168.0.178:8081/nexus/content/groups/public/com/fakesitename/poms/super/1.3/super-1.3.pom (33 KB at 157.3 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.243s
[INFO] Finished at: Sun Mar 24 22:22:01 CET 2013
[INFO] Final Memory: 6M/17M
[INFO] ------------------------------------------------------------------------

所以,我真的不知道该怎么办。我希望能够使用 settings.xml 文件中的“官方”https 地址

最佳答案

“对等方未通过身份验证”通常意味着服务器提供的 SSL 证书不是由客户端 JRE 知道的授权机构签名的(例如自签名)。

如果是这种情况,您需要将 CA 证书导入 JRE 的信任库(或用您自己的信任库覆盖它)。

关于maven - 如何配置 maven settings.xml 以访问 apache 代理背后的 nexus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604227/

相关文章:

java - 如何使 uploadArchives 依赖于另一个任务?

maven - 存储没有版本号的 Nexus/Maven Artifact

Apache 使用 mod_proxy 和大文件返回 502 Bad Gateway

java - 如何删除我的 Jetty webapp url 的根元素?

java - Spring Boot、ActiveMQ、修改代理 URL

maven-2 - 无法从 Nexus 获得正确的软件包?错误 "mvn help:effective-settings"

nexus - 使用 Nexus3 API 如何获取存储库中的工件列表

apache - Tomcat Apache 端口 80 端口 8080

apache - 如何屏蔽 apache 子域后面的 tomcat 应用程序?

java - 导入 Spring 的 ReflectionTestUtils 类时遇到问题