我正在寻找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 ~(?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 /根位置
最佳答案
location指令是/ artifactory /而不是/因为您正在使用公共上下文.也就是说,对Artifactory的所有访问都将采用servername / artifactory /而不是servername /的形式.这样做的好处是,您可以为多个应用程序使用相同的URL,例如,如下所示:
原文链接:https://www.f2er.com/nginx/434915.htmlArtifactory – >服务器名/ artifactory的/
jenkins – >服务器名/jenkins/
我的自定义服务 – >服务器名/ MyApp的/
换句话说,它允许您为不同的应用程序重用具有不同上下文的相同服务器名称(和端口).如果您的反向代理正在根级别进行侦听,则所有请求都将转发到Artifactory.
现在回答您的具体问题,为什么Artifactory会这样做?这可能是为了清晰/一致,因为Artifactory附带的默认tomcat使用artifactory关键字作为其上下文.您当然可以自由地从Nginx配置中删除公共上下文,并且只要您进行了所有必要的更改(从重写,位置和X-Artifactory-Override-中删除它),所有内容都将按预期使用根上下文servername /工作. BASE-URL).