Troubleshooting Umami Analytics: Resolving Unknown User Country Issue with Proxy Protocol on OCI
Hisyam Johan
Posted on September 23, 2024
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.
Locate the Nginx Ingress controller ConfigMap.
Add the following line to the data section:
data:
use-proxy-protocol: "true"
- After updating the ConfigMap, restart the Nginx Ingress controller deployment for the changes to take effect:
kubectl rollout restart deployment <nginx-ingress-controller-deployment>
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.
Open your Nginx configuration file.
Modify the
server
block to include theproxy_protocol
directive, like so:
http {
# Other settings...
server {
listen 80 proxy_protocol;
listen 443 ssl proxy_protocol;
# Other settings...
}
}
- After updating the configuration, restart Nginx to apply the changes:
sudo systemctl restart nginx
I think this implementation also applied to other analytic server.
Posted on September 23, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.