Cookie rejected: Illegal path attribute /nexus. Path of orig

问题描述

通过执行“mvn clean deploy” 命令 将 Maven 项目发布到 Nexus 私服时,控制台输出了如下警告信息:

[INFO] Downloaded: dav:${groupId}/${artifactId}/${version}/maven-metadata.xml (2 KB at 10.5 KB/sec)[INFO] Uploading: ${groupId}/${artifactId}/${version}/${artifactId}-xxx.jar2015-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: ${groupId}/${artifactId}/${version}/${artifactId}-3.0.4-20150319.022040-25.jar (60 KB at 76.6 KB/sec)

系统环境

私服是搭建在一台 Windows Server 2008 的阿里云服务器上,Nexus 的版本为2.8.1,通过 Ngnix 1.7.10 进行反向代理( 直接指向 :8081/nexus)。 开发机是 Windows 7,,使用 Maven 版本为 3.0.4。

问题分析

根据控制台输出的警告信息可知,这是 cookie 的 path 属性不一致,需要 path=/nexus 下的 cookie,而现在对应的路径/content/repositories/snapshots/${groupId}/${artifactId}/${version}/ 中并不包含 /nexus 这一级。根据这个判断,于是我将 snapshots 的 URL 由 改为:8081/nexus/content/repositories/snapshots,然后重新执行 mvn clean deploy 发布 jar 包到私服,这一次的发布过程中果然没有出现任何警告信息。因为修改之后的这个 URL 是没有通过 Nginx 作代理进行转发的,所以,现在已经可以确定问题是出在 Nginx 的代理配置这一块了。

解决方案

问题产生的原因已经找到了,接下来就是根据问题原因寻找对应的解决方案了。经过查阅资料得知,只需要在 Nginx 的代理配置中增加 cookie 的 path 映射关系即可,官方文档请参见:ngx_http_proxy_module 模块中的 proxy_cookie_path,修改后的配置如下:

# Mavenserver {listen80;server_name maven.mysite.com;location / {proxy_pass:18081/nexus/;proxy_redirectoff;proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_headerUpgrade $http_upgrade;proxy_cookie_path/nexus /;…… ……}location ~ ^/nexus/(.*)$ {return301 /$1;}}另外,如果您是使用的 Apathe 做反向代理,那应该通过ProxyPassReverseCookiePath 进行配置,如:

ProxyPassReverseCookiePath /nexus /

往事是尘封在记忆中的梦,而你是我唯一鲜明的记忆,

Cookie rejected: Illegal path attribute /nexus. Path of orig

相关文章:

你感兴趣的文章:

标签云: