I’m running an Nginx container using Ansible and Docker. I have configured Nginx to allow anonymous access to the /metrics endpoint and set up a reverse proxy. Despite this, accessing the /metrics endpoint results in an HTTP 302 redirect to an authentication page.
Nginx Configuration:
Here’s the relevant portion of my Nginx configuration:
# Loop through applications
% for app in nginx_apps %}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ app.server_name }};
set $app{{ loop.index }} {{ app.container_url }};
location / {
proxy_pass $app{{ loop.index }};
}
location /metrics {
allow all;
proxy_pass {{ app.container_url }}/metrics;
}
}
{% endfor %}
# Dedicated server block for metrics
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
location ~ ^/metrics/(.+)$ {
allow all;
set $app_name $1;
proxy_pass http://$app_name:8080/metrics;
}
}
What could be causing the HTTP 302 redirect despite allowing anonymous access in the Nginx configuration? How can I ensure that the /metrics endpoint is accessible without redirection?
Allowed Anonymous Access to /metrics endpoint in my application
Soundarya Venkatesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.