问题叙述性说明
通过运行“mvn clean deploy” 命令 将 Maven 项目公布 Nexus 当PW。举例控制台输出以下警告消息:
[INFO] Downloaded: dav:http://maven.mysite.com/content/repositories/snapshots/${groupId}/${artifactId}/${version}/maven-metadata.xml (2 KB at 10.5 KB/sec) [INFO] Uploading: http://maven.mysite.com/content/repositories/snapshots/${groupId}/${artifactId}/${version}/${artifactId}-xxx.jar 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/snapshots/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/snapshots/${groupId}/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/snapshots/${groupId}/${artifactId}/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/snapshots/${groupId}/${artifactId}/${version}/" 2015-3-19 10:20:47 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders 警告: Cookie rejected: "$Version=0; rememberMe=deleteMe; $Path=/nexus". Illegal path attribute "/nexus". Path of origin: "/content/repositories/snapshots/${groupId}/${artifactId}/${version}/${artifactId}-xxx.jar" …… …… [INFO] Uploaded: http://maven.mysite.com/content/repositories/snapshots/${groupId}/${artifactId}/${version}/${artifactId}-3.0.4-20150319.022040-25.jar (60 KB at 76.6 KB/sec)
系统环境
私服是搭建在一台 Windows Server 2008 的阿里云server上,Nexus 的版本号为 2.8.1,通过 Ngnix 1.7.10 进行反向代理(http://maven.mysite.com/ 直接指向 http://127.0.0.1:8081/nexus)。
开发机是 Windows 7,使用 Maven 版本号为 3.0.4。
问题分析
依据控制台输出的警告信息可知,这是 cookie 的 path 属性不一致,须要 path=/nexus 下的 cookie,而如今相应的路径 /content/repositories/snapshots/${groupId}/${artifactId}/${version}/ 中并不包括 /nexus 这一级。
依据这个推断,于是我将 snapshots 的 URL 由 http://maven.gboat.xyz/content/repositories/snapshots 改为 http://maven.gboat.xyz:8081/nexus/content/repositories/snapshots,然后又一次运行 mvn clean deploy 公布 jar 包到私服,这一次的公布过程中果然没有出现不论什么警告信息。
由于改动之后的这个 URL 是没有通过 Nginx 作代理进行转发的,所以。如今已经能够确定问题是出在 Nginx 的代理配置这一块了。
解决方式
问题产生的原因已经找到了。接下来就是依据问题原因寻找相应的解决方式了。
经过查阅资料得知。仅仅须要在 Nginx 的代理配置中添加 cookie 的 path 映射关系就可以。官方文档请參见:ngx_http_proxy_module 模块中的 proxy_cookie_path,改动后的配置例如以下:
# Maven server { listen 80; server_name maven.mysite.com; location / { proxy_pass http://127.0.0.1:18081/nexus/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_cookie_path /nexus /; …… …… } location ~ ^/nexus/(.*)$ { return 301 /$1; } }另外,假设您是使用的 Apathe 做反向代理。那应该通过 ProxyPassReverseCookiePath 进行配置,如:
ProxyPassReverseCookiePath /nexus /
參考资料:http://books.sonatype.com/nexus-book/reference/install-sect-proxy.html
版权声明:本文博主原创文章。博客,未经同意不得转载。