ARTIFACTORY: How to Debug Nginx Reverse Proxy Issues

Yonatan Brand
2023-01-22 11:07

There are many reasons why you should use a reverse proxy in front of our JFrog product. The two most common scenarios are when:

  1. You have several nodes and you want to set up a load balancer between them
  2. You need to redirect requests to a specific port

In some instances, requests won't reach a JFrog product as a result of a reverse proxy issue.
Accordingly, it's wise to enable Nginx logging, as it may help you to identify the root cause of of a
given problem. You can do this by adding the following lines under the server block of your
configuration file:access_log /var/log/nginx/$NAME_OF_LOG_FILE-access.log timing; //This will enable the Nginx access log

error_log /var/log/nginx/$NAME_OF_LOG_FILE-error.log debug; //This will enable the Nginx error log with debug mode

Following is a sample of an Nginx log for a two-node Artifactory cluster (of Artifactory version 6.x):

## add High Availability entries when Artifactory HA is configure
upstream artifactory {
ip_hash;
server hts-il-art-p:8081;
server hts-il-art-s:8081;
}

## server configuration
server {
listen 80 ;
server_name hts-il-db-lb;
proxy_http_version 1.1;
if ($http_x_forwarded_proto = '') {
set $http_x_forwarded_proto $scheme;
}

## Application specific logs
access_log /var/log/nginx/hts-il-db-lb-access.log timing;
error_log /var/log/nginx/hts-il-db-lb-error.log debug;
rewrite ^/$ /artifactory/webapp/ redirect;
rewrite ^/artifactory/?(/webapp)?$ /artifactory/webapp/ redirect;
rewrite ^/(v2)/(.*) /artifactory/$1/$2;
chunked_transfer_encoding on;
client_max_body_size 0;
location /artifactory/ {
proxy_read_timeout 2400s;
proxy_pass_header Server;
proxy_cookie_path ~*^/.* /;
if ( $request_uri ~ ^/artifactory/(.*)$ ) {
proxy_pass https://artifactory/artifactory/$1;

}
proxy_pass https://artifactory/artifactory/;
proxy_next_upstream http_503 non_idempotent;
proxy_set_header X-Artifactory-Override-Base-Url
$http_x_forwarded_proto://$host:$server_port/artifactory;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /artifactory/(api/replication/replicate/file/streaming) {
proxy_pass https://artifactory:8081/artifactory/$1;
proxy_buffering off;
}
}

Published: Apr. 22, 2019
Last updated: May 24, 2021

Keywords: Reverse-Proxy, Nginx, Debug