The original post: /r/nginx by /u/TaurusFervant on 2024-09-24 17:02:19.
0
When I host my kafka server on vps and add the nginx server for the control center authentication, I get the error 404 page not found. However this same setup works fine on my local machine when I change the nginx.conf file and replcae evey ip address with my localhost. I am using docker containers and I have 5 docker containers 2 of them are kafka brokers, 1 is zookeepr, 1 is the control center and 1 is the nginx server. Everything is working fine, the niginx logs is saying that its ready to use.
this is my nginx.conf file
user nginx;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# SSL settings
ssl_certificate /etc/nginx/ssl/ssl_cert.pem;
ssl_certificate_key /etc/nginx/ssl/ssl_cert.key;
# Gzip Settings (optional)
gzip on;
server {
listen 443 ssl;
server_name <VPS_ADDRESS>; # Change to your local IP or hostname if needed
# Proxy settings for Control Center
location / {
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass ; # Forward requests to Control Center
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;
}
# Error page for 404
error_page 404 /404.html;
}
server {
listen 80;
server_name <VPS_ADDRESS>; # Change to your local IP or hostname if needed
# Redirect all HTTP to HTTPS
return 301 https://$host$request_uri;
}
}
http://control-center:9021
and these are docker containers for nginx and control center:
control-center:
image: confluentinc/cp-enterprise-control-center:7.4.0
hostname: control-center
container_name: control-center
depends_on:
- zookeeper
- broker1
- broker2
ports:
- "9021:9021" # Control Center UI port
environment:
CONTROL_CENTER_BOOTSTRAP_SERVERS: 'broker1:29092,broker2:29093'
CONTROL_CENTER_ZOOKEEPER_CONNECT: 'zookeeper:2181'
CONTROL_CENTER_CONNECT_CONNECT_CLUSTER: 'localhost:8083'
CONTROL_CENTER_KSQL_KSQLDB1_URL: "http://ksqldb-server:8088"
CONTROL_CENTER_SCHEMA_REGISTRY_URL: "http://schema-registry:8081"
CONTROL_CENTER_REPLICATION_FACTOR: 1
CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1
CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1
CONFLUENT_METRICS_TOPIC_REPLICATION: 1
CONTROL_CENTER_SSL_KEYSTORE_LOCATION: '/etc/ssl/keystore.jks' # Path to keystore in the container
CONTROL_CENTER_SSL_KEYSTORE_PASSWORD: 'key_stroe_pw' # Keystore password
CONTROL_CENTER_SSL_TRUSTSTORE_LOCATION: '/etc/ssl/truststore.jks' # Path to truststore in the container
CONTROL_CENTER_SSL_TRUSTSTORE_PASSWORD: 'trust_store_pw' # Truststore password
volumes:
- ./keystore.jks:/etc/ssl/keystore.jks:ro # Mount the keystore into the container
- ./truststore.jks:/etc/ssl/truststore.jks:ro # Mount the truststore into the container (if applicable)
networks:
- confluent
healthcheck:
test: ["CMD", "curl", "-f", "https://localhost:9021"]
interval: 30s
timeout: 10s
retries: 5
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro # NGINX config
- ./htpasswd:/etc/nginx/.htpasswd:ro # Password file for authentication
- ./ssl:/etc/nginx/ssl:ro # Mount the SSL certificates
ports:
- "443:443" # Expose SSL on port 443
- "8080:8080" # Redirect HTTP to HTTPS
depends_on:
- control-center
networks:
- confluent
I can access the control center directly from my local machine through this <VPS\_ADDRESS>:9021 but I want an authentication enabled so that when I access this http://<VPS\_ADDRESS> i get a prompt to add username and password and the redirect to control center.
I have tried to access the control center from nginx container, I am getting 200 response message on curl http://control-center:9021