Nginx位置/ vs/artifactory

use*_*mda 8 nginx artifactory docker-registry nginx-location

我正在寻找nginx配置来设置docker存储库

###########################################################
## this configuration was generated by JFrog Artifactory ##
###########################################################

## add ssl entries when https has been set in config
ssl_certificate      /etc/nginx/ssl/demo.pem;
ssl_certificate_key  /etc/nginx/ssl/demo.key;
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers   on;
## server configuration
server {
    listen 443 ssl;
    listen 80 ;
    server_name ~(?<repo>.+)\.art.local art.local;

    if ($http_x_forwarded_proto = '') {
        set $http_x_forwarded_proto  $scheme;
    }
    ## Application specific logs
    ## access_log /var/log/nginx/art.local-access.log timing;
    ## error_log /var/log/nginx/art.local-error.log;
    rewrite ^/$ /artifactory/webapp/ redirect;
    rewrite ^/artifactory/?(/webapp)?$ /artifactory/webapp/ redirect;
    rewrite ^/(v1|v2)/(.*) /artifactory/api/docker/$repo/$1/$2;
    chunked_transfer_encoding on;
    client_max_body_size 0;
    location /artifactory/ {
    proxy_read_timeout  900;
    proxy_pass_header   Server;
    proxy_cookie_path   ~*^/.* /;
    proxy_pass          http://localhost:8081/artifactory/;
    proxy_set_header    X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory;
    proxy_set_header    X-Forwarded-Port  $server_port;
    proxy_set_header    X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_set_header    Host              $http_host;
    proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么location指令设置为/ artifactory Vs /根位置

小智 0

位置指令是/artifactory/而不是/因为您正在使用公共上下文。也就是说,所有对 Artifactory 的访问都将是servername/artifactory/和 not的形式servername/。这样做的优点是您可以对多个应用程序使用相同的 URL,例如,如下所示:

Artifactory -> servername/artifactory/ Jenkins ->servername/jenkins/ 我的定制服务 ->servername/myapp/

换句话说,它允许您在不同的应用程序的不同上下文中重用相同的服务器名称(和端口)。如果您的反向代理在根级别侦听,则所有请求都将转发到 Artifactory。

现在回答你的具体问题,Artifactory 为什么这样做?这可能是为了清晰/一致性,因为 Artifactory 附带的默认 tomcat 使用 artifactory 关键字作为其上下文。当然,您可以自由地从 NGINX 配置中删除公共上下文,servername/只要您进行了所有必要的更改(从重写、位置和 X-Artifactory-Override-Base- 中删除它),根上下文的一切都会按预期工作。网址)。