2016-09-30 64 views
8

我在看nginx的配置,以建立一個碼頭工人庫Nginx的位置/ VS/artifactory的

########################################################### 
## 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; 
    } 
} 

爲什麼位置指令設定/ artifactory的VS /根位置

+0

個人喜好。有時應用程序通過它們的URI訪問,有時通過子域訪問應用程序(例如,artifactory.example.com)。使用許多子域名還有其他一些小問題,但這不是這裏的主題。 –

回答

0

位置指令是/artifactory/而不是/,因爲您正在使用公共上下文。也就是說,所有對Artifactory的訪問將以servername/artifactory/的形式進行,而不是servername/。這樣做,你可以使用相同的網址用於多個應用,例如優勢,是這樣的:

Artifactory的 - >servername/artifactory/ 詹金斯 - >servername/jenkins/ 我的自定義服務 - >servername/myapp/

換句話說,它允許您針對不同的應用程序重用具有不同上下文的相同服務器名稱(和端口)。如果您的反向代理正在監聽根級別,則所有請求都將被轉發給Artifactory。

現在要回答您的具體問題,爲什麼Artifactory會這樣做?由於Artifactory附帶的默認tomcat在其上下文中使用artifactory關鍵字,因此可能會使其清晰度/一致性更高。您當然可以自由地從NGINX配置中刪除公共上下文,如果您進行了所有必要的更改(將其從重寫,位置和X-Artifactory-Override-Base中移除),則所有內容都將按照預期與根環境servername/一起工作-url)。