使用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.com-access.log
## error_log /var/log/nginx/my.artifactory.com-error.log;
位置~ * ^ / (402 \ 500 \ . htm | 502 | . htm \ . htm 503 | \ . htm | 503 -迁移\ . htm) $ {
根/usr/share/nginx/html;
}
如果($http_x_forwarded_proto != "https") {
重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1 redirect;
^/$ $scheme://$host/artifactory/webapp/#/home redirect;
}
如果($http_x_forwarded_proto = "https") {
重写^/$ https://$host/artifactory/webapp/#/home redirect;
}
#### docker存储库名称#####
重写^ / (v1 | v2) / (. *) / artifactory / api /码头工人/ < docker-repo-name > / 1 / 2美元;
header_filter_by_lua”
local myProto = ngx.var["http_x_forwarded_proto"]
如果myProto == "https"则
local locHeader = ngx.header["Location"]
如果loheader,那么
如果type(locHeader) == "string"则
本地位置= ngx.re。match(locHeader, "http[s]?://(.*)", "io")
如果位置那么
ngx。header["Location"] = "https://" ..位置[1]
结束
结束
结束
结束
”;
地点/人工{
proxy_http_version 1.1;
proxy_pass http://localhost: 8081;
proxy_intercept_errors;
proxy_pass_header服务器;
proxy_connect_timeout 75年代;
proxy_send_timeout 2400年代;
proxy_read_timeout 2400年代;
proxy_set_header $ Host;
$proxy_add_x_forwarded_for;
$http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr
$http_x_forwarded_proto://$host/artifactory;
}
}
评论:
这个配置中最重要的部分是if语句。
它的主要目的是保持通过负载均衡器的请求的协议(如果它是http或https)。
如果($http_x_forwarded_proto != "https") {
重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1 redirect;
^/$ $scheme://$host/artifactory/webapp/#/home redirect;
}
如果($http_x_forwarded_proto = "https") {
重写^/$ https://$host/artifactory/webapp/#/home redirect;
}
请注意,重写规则还指定了重定向的完整路径以及保留协议。
docker存储库的重写规则从授权生成器配置文件。
对于本例,我们使用了一个v2 api存储库。
在这种情况下,具有'/v2/'模式的请求将被重定向到docker存储库。
