How do I debug NGINX reverse proxy issues?

Yonatan Brand
2019-04-22 11:23

There are a lot of reasons why we should use a reverse proxy in front of our JFrog Product. In front of you the most two common scenarios:

  1. We have several nodes and we want to create a load-balancer between them
  2. Redirect requests to a specific port

In some cases we can experience the behaviour of requests not reaching to our JFrog product. This can be due to reverse proxy issues. 

It may be helpful to enable logging for Nginx to try better investigate the root cause of our issue. 
We can do that by adding to our configuration file the following lines under the "server" block:

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

For example, below is a sample of nginx log for Artifactory cluster of two nodes: 

## 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          http://artifactory/artifactory/$1;
    }
    proxy_pass          http://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          http://artifactory:8081/artifactory/$1;
    proxy_buffering off;
    }
}