Nginx Unable to Proxy Keycloak on Port 8080 – Connection Refused
Environment Details
- Keycloak: 24.0.0
- Nginx: 1.27.3
Problem Description
I’m experiencing an issue where Nginx can successfully proxy the backend on port 8081, but fails to proxy Keycloak running on port 8080.
Detailed Observations
Keycloak Endpoint (:8080)
curl -I https://xxxx.de/auth/
HTTP/1.1 404 Not Found
Server: nginx/1.27.3
Date: Sat, 07 Dec 2024 11:12:46 GMT
Content-Type: application/json
Connection: keep-alive
Backend Endpoint (:8081)
bashCopycurl -I https://xxxx.de/api/
HTTP/1.1 401
Server: nginx/1.27.3
Date: Sat, 07 Dec 2024 11:16:23 GMT
Connection: keep-alive
# ... other headers
Nginx Error Log
Copy2024/12/07 12:12:30 [error] 1818792#1818792: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 194.92.121.85, server: www.xxxx.de, request: "HEAD /auth/ HTTP/1.1", upstream: "http://[::1]:8080/auth/", host: "xxxx.de"
# ... similar errors repeated
Current Configuration
Podman Compose File
yamlCopyversion: '3.9'
services:
keycloak:
image: quay.io/keycloak/keycloak:24.0.0
container_name: keycloak
ports:
- "8080:8080"
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=123123
- PROXY_ADDRESS_FORWARDING=true
- KC_PROXY_HEADERS=forwarded
command: ["start-dev"]
# ... other services
Nginx Configuration
nginxCopylocation /auth/ {
add_header X-Debug-Referer $http_referer;
add_header Access-Control-Allow-Origin *;
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Questions
Why is Nginx unable to connect to the Keycloak container on port 8080?
What could be causing the connection refused error?
Are there any specific configuration steps I'm missing?
I've verified that:
Keycloak container is running
Port 8080 is exposed in the Podman compose file
Nginx configuration appears correct
Any help in diagnosing and resolving this connection issue would be greatly appreciated.
Copy
I've transformed the original text into a Stack Overflow-friendly format with:
- Clear section headings
- Code blocks for different configurations
- Highlighted key information
- Structured problem description
- Specific questions to help potential responders
The formatting makes the issue clear, provides context, and makes it easy for someone to understan