How to remove “artifactory” from the Context URL in Artifactory 7

David Pinhas
2020-06-29 19:05

How to remove “artifactory” from the Context URL in Artifactory 7

Important Note – This Knowledge Base only applies to self-managed Artifactory instances and not Artifactory SaaS instances.

JFrog Artifactory prior to version 7.0 allowed removing the artifactory context either by modifying the Tomcat configuration or via a reverse proxy. Due to architectural changes, this is no longer supported with versions of Artifactory 7.0+ as mentioned here. It is still technically possible to accomplish this setup with a reverse proxy, though it carries limitations and may break in a future release of Artifactory.

In this article, we will share samples of Apache and Nginx configurations in order to remove the context.
Please Note – This is not recommended, as removing “artifactory” from the context URL will not be supported in the future. But, these configurations can be used as a Stop-Gap to give you time to adjust to the new method.

The solution contained below should only be used if:

  • You are currently using the ‘root’ context in a version of Artifactory prior to 7.0
  • You have many embedded URLs without the ‘artifactory’ context and cannot easily change them
  • You need to upgrade to Artifactory 7
  • You plan to migrate to the ‘artifactory’ context but need some time to do so

What does the solution do?

  • Allows your hard-coded contextless URLs to continue to work with Artifactory 7 (with some limitations listed below)
  • Allows you to use the “artifactory” context so you can gradually move away from the contextless URLs. 
    • This means your artifacts will be available both as https://example.com/reponame/myfile.txt and https://example.com/artifactory/reponame/myfile.txt
  • The UI “Set Me Up” feature will now include the “artifactory” context, so any new users will be set up with the correct method moving forward.
  • You may enable special logging to see what IP addresses/users are still using the contextless URLs

Solution limitations

The solution has limitations where certain repositories names may not be accessible if they are named after one of the following contexts: 

  • ui
  • artifactory
  • router
  • access
  • metadata
  • replicator
  • v2
  • xray
  • mc
  • insight
  • insight-scheduler
  • insight-executor
  • distribution

Some of these contexts may not be needed, review the sample configurations for exact details. 

Sample Configurations

This solution is only a template, you will need to modify it to your particular configuration. 

The default settings will work if you are running the reverse proxy on the same machine as Artifactory with all the default ports. 

If you are using products other than Artifactory, you will need to uncomment those product sections. 

If you want to add SSL, run on a different port (the default is 80), support the subdomain Docker method or work in HA mode, you will need to make slight adjustments.

Apache Example:

## Application specific logs
#Define APACHE_LOG_DIR /var/log/httpd
# If changing the ports to anything other than 443 or 80, you must also modify
# X-JFrog-Override-Base-Url and X-Artifactory-Override-Base-Url
# Add if Listen 80 is not alredy present in Apache config or if changing the port
# Listen 80
<VirtualHost *:80>
## Add ':%{my_server_port}e' to the end of line if it is running on any port other than 80 or 443
Define base_url %{my_scheme}e://%{my_custom_host}e
ProxyPreserveHost On
# Set the server name here
ServerName localhost
ServerAdmin server@admin
## Application specific logs
## ErrorLog ${APACHE_LOG_DIR}/jfrog-error.log
## CustomLog ${APACHE_LOG_DIR}/jfrog-access.log combined
AllowEncodedSlashes On
RewriteEngine on
RewriteCond %{SERVER_PORT} (.*)
RewriteRule (.*) - [E=my_server_port:%1]
## NOTE: The 'REQUEST_SCHEME' Header is supported only from apache version 2.4 and above
RewriteCond %{REQUEST_SCHEME} (.*)
RewriteRule (.*) - [E=my_scheme:%1]
RewriteCond %{HTTP_HOST} (.*)
RewriteRule (.*) - [E=my_custom_host:%1]
RewriteRule ^(/)?$ /ui/ [R,L]
RewriteRule ^/ui$ /ui/ [R,L]
RequestHeader set Host %{my_custom_host}e
RequestHeader set X-Forwarded-Port %{my_server_port}e
## NOTE: {my_scheme} requires a module which is supported only from apache version 2.4 and above
RequestHeader set X-Forwarded-Proto %{my_scheme}e
ProxyPassReverseCookiePath / /
ProxyRequests off
ProxyPreserveHost on
# Artifactory as the root
<Location "/">
RequestHeader set X-Artifactory-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/artifactory/
ProxyPassReverse http://${ARTIFACTORY}/artifactory/
</Location>
# If using the path method for Docker
<Location "/v2/">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/v2/
ProxyPassReverse http://${ARTIFACTORY}/v2/
</Location>
# Artifactory context
<Location "/artifactory/">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/artifactory/
ProxyPassReverse http://${ARTIFACTORY}/artifactory/
</Location>
# Artifactory microservices
<LocationMatch "^/(ui|router|access|metadata|replicator)/.*$">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY_ROUTER}
ProxyPassReverse http://${ARTIFACTORY_ROUTER}
</LocationMatch>
# PRODUCT SPECIFIC LOCATIONS - START
# These locations are only needed if using specific JFrog Products
# Uncomment if using Xray
#<Location "/xray/">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}/xray/
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}/xray/
#</Location>
# Uncomment if using JFrog distribution
#<Location "/distribution/">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}/distribution/
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}/distribution/
#</Location>
# Uncomment if using JFrog Mission Control
#<LocationMatch "^/(mc|insight|insight-scheduler|insight-executor)/.*$">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}
#</LocationMatch>
# PRODUCT SPECIFIC LOCATIONS - END
</VirtualHost>

The above example will require Apache2 version 2.4 and above, as it relies on “REQUEST_SCHEME” and “my_scheme” module is supported from version 2.4.

Furthermore, in case you have additional JFrog Products integrated with the JFrog Platform, you will need to uncomment the needed Services from the bottom of this configuration.

Nginx Example:

# Artifactory port (default 8081) - REQUIRED
Define ARTIFACTORY localhost:8081
# Router port (default 8082) - REQUIRED
Define ARTIFACTORY_ROUTER localhost:8082
## Application specific logs
#Define APACHE_LOG_DIR /var/log/httpd
# If changing the ports to anything other than 443 or 80, you must also modify
# X-JFrog-Override-Base-Url and X-Artifactory-Override-Base-Url
# Add if Listen 80 is not alredy present in Apache config or if changing the port
# Listen 80
<VirtualHost *:80>
## Add ':%{my_server_port}e' to the end of line if it is running on any port other than 80 or 443
Define base_url %{my_scheme}e://%{my_custom_host}e
ProxyPreserveHost On
# Set the server name here
ServerName localhost
ServerAdmin server@admin
## Application specific logs
## ErrorLog ${APACHE_LOG_DIR}/jfrog-error.log
## CustomLog ${APACHE_LOG_DIR}/jfrog-access.log combined
AllowEncodedSlashes On
RewriteEngine on
RewriteCond %{SERVER_PORT} (.*)
RewriteRule (.*) - [E=my_server_port:%1]
## NOTE: The 'REQUEST_SCHEME' Header is supported only from apache version 2.4 and above
RewriteCond %{REQUEST_SCHEME} (.*)
RewriteRule (.*) - [E=my_scheme:%1]
RewriteCond %{HTTP_HOST} (.*)
RewriteRule (.*) - [E=my_custom_host:%1]
RewriteRule ^(/)?$ /ui/ [R,L]
RewriteRule ^/ui$ /ui/ [R,L]
RequestHeader set Host %{my_custom_host}e
RequestHeader set X-Forwarded-Port %{my_server_port}e
## NOTE: {my_scheme} requires a module which is supported only from apache version 2.4 and above
RequestHeader set X-Forwarded-Proto %{my_scheme}e
ProxyPassReverseCookiePath / /
ProxyRequests off
ProxyPreserveHost on
# Artifactory as the root
<Location "/">
RequestHeader set X-Artifactory-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/artifactory/
ProxyPassReverse http://${ARTIFACTORY}/artifactory/
</Location>
# If using the path method for Docker
<Location "/v2/">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/v2/
ProxyPassReverse http://${ARTIFACTORY}/v2/
</Location>
# Artifactory context
<Location "/artifactory/">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY}/artifactory/
ProxyPassReverse http://${ARTIFACTORY}/artifactory/
</Location>
# Artifactory microservices
<LocationMatch "^/(ui|router|access|metadata|replicator)/.*$">
RequestHeader set X-JFrog-Override-Base-Url ${base_url}
ProxyPass http://${ARTIFACTORY_ROUTER}
ProxyPassReverse http://${ARTIFACTORY_ROUTER}
</LocationMatch>
# PRODUCT SPECIFIC LOCATIONS - START
# These locations are only needed if using specific JFrog Products
# Uncomment if using Xray
#<Location "/xray/">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}/xray/
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}/xray/
#</Location>
# Uncomment if using JFrog distribution
#<Location "/distribution/">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}/distribution/
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}/distribution/
#</Location>
# Uncomment if using JFrog Mission Control
#<LocationMatch "^/(mc|insight|insight-scheduler|insight-executor)/.*$">
# RequestHeader set X-JFrog-Override-Base-Url ${base_url}
# ProxyPass http://${ARTIFACTORY_ROUTER}
# ProxyPassReverse http://${ARTIFACTORY_ROUTER}
#</LocationMatch>
# PRODUCT SPECIFIC LOCATIONS - END
</VirtualHost>

Moreover, you will need to uncomment the :$server_port (remove ;#) if it is running on any port other than 80 or 443.

As these examples will not fit every use case, you may require to modify the above examples according to your needs.

You can find the above examples in the following GitHub page.