当使用AWS-ELB负载均衡器时,如何为Artifactory Docker存储库配置反向代理?

JFrog支持
2018-11-01 29

下面是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;

Location ~* ^/(402.htm|500.htm|502.htm|503.htm|503-migrate.htm)$ {

根/usr/share/nginx/html;

If ($http_x_forwarded_proto != "https") {

重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1 redirect;

重写^/$ $scheme://$host/artifactory/webapp/#/home redirect;

If ($http_x_forwarded_proto = "https") {

重写^/$ https://$host/artifactory/webapp/#/home redirect;

#### 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"]

如果locHeader然后

if type(locHeader) == "string" then

本地位置= ngx.re。match(locHeader, "http[s]?://(.*)", "io")

如果位置那么

ngx。header["Location"] = "https://" ..位置[1]

结束

结束

结束

结束

”;

位置/artifactory {

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年代;

proxy_set_header

$proxy_add_x_forwarded_for;

proxy_set_header - forward - proto $http_x_forwarded_proto;

proxy_set_header X-Real-IP

$http_x_forwarded_proto://$host/artifactory;

评论:

该配置中最重要的部分是if语句。

它的主要目的是保持通过负载均衡器的请求的协议(如果是http或https)。

If ($http_x_forwarded_proto != "https") {

重写^/artifactory/webapp/(.*) https://$host/artifactory/webapp/$1 redirect;

重写^/$ $scheme://$host/artifactory/webapp/#/home redirect;

If ($http_x_forwarded_proto = "https") {

重写^/$ https://$host/artifactory/webapp/#/home redirect;

请注意,重写规则在保留协议的同时还指定重定向的完整路径。

的docker存储库的重写规则没有更改认证生成器配置文件

对于本例,我们使用v2 api存储库。

在这种情况下,具有'/v2/'模式的请求将被重定向到docker存储库。