Cookie rejected: Illegal path attribute "/nexus". Path of origin: "/content/" 解决方案

问题描述

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

[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 的阿里云服务器上,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

你可能感兴趣的:(maven,cookie,nexus,deploy,rejected)