Setting Up Apache HTTP Server

Using HTTP

From Artifactory version 7.0, the AJP connector is not supported.

You can set up Apache HTTP Server as a front end to Artifactory using the HTTP protocol.

Client ----------> HTTPD ----------> Artifactory
          HTTP            HTTP

When running Artifactory with Tomcat, we recommend that you set up Apache to proxy Artifactory via HTTP.

You must configure redirects correctly using the PassReverse directive, and also set the base URL in Artifactory itself so that the UI links show up correctly.

The sample virtual host assumes that Artifactory listens on port 8081 and all other services and UI are available on port 8082.

For HTTP redirects to work, you must set a PassReverse directive on Apache, otherwise the underlying container base URL is passed in redirects

In the example below it is set to

<VirtualHost *:80>
    ServerAlias *
    ServerAdmin server@admin

    ## Application specific logs
    ## ErrorLog ${APACHE_LOG_DIR}/
    ## CustomLog ${APACHE_LOG_DIR}/ 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]

    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-JFrog-Override-Base-Url %{my_scheme}e://{my_server_port}e

    ProxyPassReverseCookiePath / /
    ProxyRequests off
    ProxyPreserveHost on
    ProxyPass "/artifactory/" http://<artifactory-ip>:8081/artifactory/ connectiontimeout=5 timeout=2400
    ProxyPassReverse "/artifactory/" http://<artifactory-ip>:8081/artifactory/
    ProxyPass "/" http://<artifactory-ip>:8082/ nocanon connectiontimeout=5 timeout=2400 
    ProxyPassReverse "/" http://<artifactory-ip>:8082/

To work with NPM scoped packages, you must apply the following configurations in the SERVER block of the Apache reverse proxy configuration.

  • Set AllowEncodedSlashes to "NoDecode".

    AllowEncodedSlashes NoDecode

  • Add the "nocanon" keyword to the ProxyPass and the ProxyPassReverse directives.

    ProxyPass /artifactory/ http://localhost:8081/artifactory/ nocanon 
    ProxyPassReverse /artifactory/ http://localhost:8081/artifactory/ nocanon

Using HTTPS 

You can set up Apache with SSL (HTTPS) as a front end to Artifactory using the HTTP protocol.

Client ----------> HTTPD ----------> Artifactory
          HTTPS           HTTP
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile path/to/
    SSLCertificateKeyFile path/to/
    SSLProxyEngine on

    ## Additional reverse proxy directives

Configuring a Custom Base URL in Artifactory

When using an HTTP proxy, the links produced by Artifactory, as well as certain redirects might contain the wrong port and use http instead of https.  

Therefore, you must configure a custom base URL as follows:

  1. On the Admin tab select Configuration | General Custom Base URL field.
  2. Set the Custom Base URL field to the value used to contact Artifactory
    For example:

Please refer to General System Settings for more details about configuring the base URL.