DEV Community

Hisyam Johan
Hisyam Johan

Posted on

Troubleshooting Umami Analytics: Resolving Unknown User Country Issue with Proxy Protocol on OCI

While using Umami for analytics, I recently encountered an issue where the user country information appeared as "Unknown." After some investigation, I discovered that the problem was related to the proxy protocol not being enabled on the Oracle Cloud Infrastructure (OCI) load balancer. Here's a detailed walkthrough of the solution.

The Issue
The primary cause of the "Unknown" country error stemmed from the fact that the user’s IP address wasn't correctly forwarded to the Umami server. When using a load balancer (such as OCI’s) in front of your application, it often proxies the request. Without the proxy protocol enabled, the originating IP address is lost, resulting in missing location data in Umami.

The Solution
To resolve this issue, follow these steps:

Step 1: Enable Proxy Protocol in OCI Load Balancer
In OCI, the proxy protocol is disabled by default. You need to enable it to ensure that the original client IP is passed to your backend (Nginx in this case). Here’s how you do it:

Navigate to your OCI Load Balancer configuration.
Under the load balancer listener settings, enable the Proxy Protocol.
Once enabled, OCI will forward the original client IP along with the request to your Nginx ingress.

Step 2: Update Nginx Ingress Controller (For Kubernetes)
If you are using Nginx Ingress Controller in a Kubernetes cluster, you’ll need to update its configuration to handle the proxy protocol. This is done by modifying the Ingress Controller ConfigMap.

  1. Locate the Nginx Ingress controller ConfigMap.

  2. Add the following line to the data section:

data:
  use-proxy-protocol: "true"
Enter fullscreen mode Exit fullscreen mode
  1. After updating the ConfigMap, restart the Nginx Ingress controller deployment for the changes to take effect:
kubectl rollout restart deployment <nginx-ingress-controller-deployment>
Enter fullscreen mode Exit fullscreen mode

Step 3: Update Nginx Configuration (For Standalone Nginx)
If you are using standalone Nginx (not in a Kubernetes cluster), you need to update the Nginx configuration directly to handle the proxy protocol.

  1. Open your Nginx configuration file.

  2. Modify the server block to include the proxy_protocol directive, like so:

http {
    # Other settings...
    server {
        listen 80   proxy_protocol;
        listen 443  ssl proxy_protocol;
        # Other settings...
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. After updating the configuration, restart Nginx to apply the changes:
sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

I think this implementation also applied to other analytic server.

Top comments (0)