How can I configure Apache as Reverse Proxy for JFrog Xray

Gajapathi Kimidi
2020-02-03 07:55

Subject 

How can I configure Apache as Reverse Proxy for JFrog Xray

Resolution

In order to configure Apache as a reverse proxy for Xray, you may use the below template and place it in respective Apache directories.

################################################

# Xray Reverse Proxy https+http with Apache

################################################

<VirtualHost *:80>

  ProxyPreserveHost On

  ServerName <your_server_name>

  ServerAlias *.<your_server_name>

  ServerAdmin server@admin

  ## Application specific logs

  ## ErrorLog ${APACHE_LOG_DIR}/<your_server_name>-error.log

  ## CustomLog ${APACHE_LOG_DIR}/<your_server_name>-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 ^/$        /web/ [R,L]

  RewriteRule ^/(/)?$   /web/ [R,L]

  RewriteRule ^//web$ /web/ [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

  ProxyPass / http://<your_ip>:8000/

  ProxyPassReverse / http://<your_ip>:8000/

</VirtualHost>

<VirtualHost *:443>

  ProxyPreserveHost On

  ServerName <your_server_name>

  ServerAlias *.<your_server_name>

  ServerAdmin server@admin

  SSLEngine on

  SSLCertificateFile /etc/apache2/mycert.cert

  SSLCertificateKeyFile /etc/apache2/mykey.key

  SSLProxyEngine on

 

  ## Application specific logs

  ## ErrorLog ${APACHE_LOG_DIR}/xray1.shaibz-error.log

  ## CustomLog ${APACHE_LOG_DIR}/xray1.shaibz-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 ^/$        /web/ [R,L]

  RewriteRule ^/(/)?$   /web/ [R,L]

  RewriteRule ^//web$ /web/ [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

  ProxyPass / http://<your_ip>:8000/

  ProxyPassReverse / http://<your_ip>:8000/

</VirtualHost>