使用 Squid 作为 Maven 存储库

Ant*_* O. 11 squid maven apache-2.2

有人知道如何使用 Squid 来代理 Maven 存储库吗?

什么是配置文件?

主要问题是 maven 客户端发出带有控制缓存行为的标头的 HTTP 请求(我想绕过它)。

这是一个典型的请求:

GET /maven/proxy/jboss-public/org/richfaces/richfaces-bom/4.2.0.Final/richfaces-bom-4.2.0.Final.pom HTTP/1.1
Cache-control: no-cache
Cache-store: no-store
Pragma: no-cache
Expires: 0
Accept-Encoding: gzip
User-Agent: Apache-Maven/3.0.4 (Java 1.6.0_26; Linux 2.6.32-38-generic)
Host: 192.168.2.171
Connection: Keep-Alive
Run Code Online (Sandbox Code Playgroud)

我已经disk_cache proxy_http为此使用了 Apache HTTPD(并启用了模块),但我正在创建一个镜像,而不是一个代理。

这是配置(基于该站点):

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

# central 
ProxyPass /maven/proxy/central http://repo1.maven.org/maven2
ProxyPassReverse /maven/proxy/central http://repo1.maven.org/maven2
CacheEnable disk /maven/proxy/central

# jboss-public-repository-group 
ProxyPass /maven/proxy/jboss-public http://repository.jboss.org/nexus/content/groups/public
ProxyPassReverse /maven/proxy/jboss-public http://repository.jboss.org/nexus/content/groups/public
ProxyPassReverseCookiePath /nexus /maven/proxy/jboss-public
CacheEnable disk /maven/proxy/jboss-public

# codehaus
ProxyPass /maven/proxy/codehaus http://repository.codehaus.org/
ProxyPassReverse /maven/proxy/codehaus http://repository.codehaus.org/
CacheEnable disk /maven/proxy/codehaus

CacheDirLength 2
CacheDirLevels 3

# Override default cache expiration and control 
CacheDefaultExpire 2419200
CacheMaxExpire 2419200

# Ignore requests to not serve from cache. Maven data never changes. 
CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheStoreNoStore On

# Default max file size is 64K. Set to 1GB. 
CacheMaxFileSize 1073741824
Run Code Online (Sandbox Code Playgroud)

ETL*_*ETL 1

我建议使用像 Nexus 这样的适当存储库,它将提供更大的灵活性,例如将中央 Maven 与您自己的本地工件组合到一个存储库中,在第一次请求时缓存从中央下载的工件(因此您不需要托管所有工件,仅那些您需要的),保护您免受中央工件删除(想想 NPM leftpad 惨败),使您能够防止使用某些工件(假设有一个存在安全缺陷的损坏工件,您可以阻止所有用户使用它) 。

而且,最重要的是,您的用户不必浪费时间为 Maven/Gradle/等设置代理配置。有时这可能很棘手......

但如果你必须在 Squid 中执行此操作:

将允许的域放入/etc/squid/mavendomains.list.

squid.conf(或者如果您有包含文件...):

acl maven-domains dstdomain "/etc/squid/mavendomains.list"
acl allowed-networks src x.x.x.x/x
http_access allow allowed-networks maven-domains
Run Code Online (Sandbox Code Playgroud)