How to work with a Repository Path method and Apache as a reverse proxy?

Shai Ben-Zvi
2019-01-09 10:58

Subject 

How to work with the Repository Path method and Apache as a reverse proxy?

Requirements

– Apache reverse proxy version 2.4 and above

Description

Please note that a Repository Path method will help you to work with Docker against Artifactory without a reverse proxy (see related wiki page).
However, in case you choose to work with Apache as a reverse proxy and with the Repository Path method, the below configuration template will help you set it up (tested on 6.5.9).

Instructions

Open Artifactory UI and navigate to the Admin tab -> Configuration -> HTTP settings and make sure that 'Docker Access Method' is set to 'Repository Path'.
On the 'Server Provider' (under Reverse Proxy Settings') set to 'Embedded Tomcat' and click on Save.

The last step is to copy the following template configuration file to your Apache reverse configuration and replace the bolded text according to your requirements:

<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/ http://<internal-artifactory-address>/artifactory/
    ProxyPassReverse /artifactory/ http://<internal-artifactory-address>/artifactory/

    ProxyPass /           http://<internal-artifactory-address>/artifactory/
    ProxyPassReverse /    http://<internal-artifactory-address>/artifactory/
</VirtualHost>