ARTIFACTORY: How to Use the Repository Path Method with an Apache Reverse Proxy

Shai Ben-Zvi
2023-01-22 11:11

Relevant versions: This information pertains to Artifactory 6.x and Apache Reverse Proxy versions 2.4 and above

The Repository Path method will help you to work with Docker against Artifactory without a reverse proxy. However, should you choose to deploy an Apache reverse proxy in conjunction with this method, use the configuration template below to set everything up (tested on Artifactory version 6.5.9).

Start by opening your Artifactory UI and navigating to the Admin tab > Configuration > HTTP settings and verify that your Docker Access Method is set to Repository Path. Also, under Reverse Proxy Settings, set your Server Provider to Embedded Tomcat, and then click Save. Finally, copy the following configuration template file to your Apache reverse configuration, replacing the text in bold to suit your environment:

<VirtualHost *:80>

    ProxyPreserveHost On

    ServerName <your-external-dns>
    ServerAlias *.<your-external-dns>
    ServerAdmin server@admin

    ## Application specific logs
    ## ErrorLog ${APACHE_LOG_DIR}/art.local-error.log
    ## CustomLog ${APACHE_LOG_DIR}/art.local-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 ^/$                /artifactory/webapp/ [R,L]
    RewriteRule ^/artifactory(/)?$      /artifactory/webapp/ [R,L]
    RewriteRule ^/artifactory/webapp$   /artifactory/webapp/ [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
    RequestHeader set X-Artifactory-Override-Base-Url %{my_scheme}e://<internal-artifactory-address>:%{my_server_port}e/artifactory
    ProxyPassReverseCookiePath /artifactory /artifactory

    ProxyRequests off
    ProxyPreserveHost on
    ProxyPass /artifactory/ https://<internal-artifactory-address>/artifactory/
    ProxyPassReverse /artifactory/ https://<internal-artifactory-address>/artifactory/

    ProxyPass /           https://<internal-artifactory-address>/artifactory/
    ProxyPassReverse /    https://<internal-artifactory-address>/artifactory/


Published: Jan. 9, 2019
Last Updated: May. 30, 2021

Keywords: Reverse Proxy, Apache, Docker