当使用AWS-ELB负载均衡器时,如何为Artifactory Docker存储库配置反向代理?
下面是NGINX反向代理配置文件的基本示例。
本例中80端口仅作为参考。它是AWS-ELB为Artifactory设置的端口。
此配置使用LUA模块(使用该模块的部分以粗体标记)。建议使用它,尽管它不是强制性的。
服务器{
听80;
server_tokens;
####服务器名称#####
server_name< my.artifactory.com >;
client_max_body_size 0;
##应用程序特定的日志
## access_log /var/log/nginx/my.artifactory. log;
## error_log /var/log/nginx/my.artifactory. log;
位置~* ^/(402.htm|500.htm|502.htm|503.htm|503- migration .htm)$ {
根/usr/share/nginx/html;
}
如果($http_x_forwarded_proto != "https") {
重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1重定向;
重写^/$ $scheme://$host/artifactory/webapp/#/home重定向;
}
If ($http_x_forwarded_proto = "https") {
重写^/$ https://$host/artifactory/webapp/#/home重定向;
}
#### docker存储库名称#####
重写^/(v1|v2)/(.*) /artifactory/api/docker/< docker-repo-name >/ 1 / 2美元;
header_filter_by_lua”
local myProto = ngx.var["http_x_forwarded_proto"]
如果myProto == "https"那么
local locHeader = ngx.header["Location"]
if locHeader then
if type(locHeader) == "string" then
本地位置= ngx.re。match(locHeader, "http[s]?://(.*)", "io")
如果位置,那么
ngx。header["Location"] = "https://" ..位置[1]
结束
结束
结束
结束
”;
地点/工厂{
proxy_http_version 1.1;
proxy_pass https://localhost: 8081;
proxy_intercept_errors;
proxy_pass_header服务器;
proxy_connect_timeout 75年代;
proxy_send_timeout 2400年代;
proxy_read_timeout 2400年代;
主机$ Host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host/artifactory;
}
}
评论:
这个配置中最重要的部分是if语句。
它的主要目的是保持通过负载均衡器的请求的协议(如果它是http或https)。
如果($http_x_forwarded_proto != "https") {
重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1重定向;
重写^/$ $scheme://$host/artifactory/webapp/#/home重定向;
}
If ($http_x_forwarded_proto = "https") {
重写^/$ https://$host/artifactory/webapp/#/home重定向;
}
请注意,重写规则在保留协议的同时还指定了重定向的完整路径。
docker存储库的重写规则没有从认证生成器配置文件.
对于本例,我们使用了v2 api存储库。
在这种情况下,具有'/v2/'模式的请求将被重定向到docker存储库。
