Nginx位置/ vs / artifactory

时间:2016-09-30 14:21:08

标签: 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;
    }
}

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

1 个答案:

答案 0 :(得分:0)

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

Artifactory - &gt; servername/artifactory/ 詹金斯 - &gt; servername/jenkins/ 我的自定义服务 - &gt; servername/myapp/

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

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