- Notifications
You must be signed in to change notification settings - Fork2.6k
Issues with HTTPS Requests and Routes in APISIX Configuration (Docker Setup)#11966
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi everyone, I am currently working on setting up APISIX with Docker for handling HTTP and HTTPS requests, but I’m facing a few issues with serving HTTPS requests and routes defined in my routes.yaml. Here’s a breakdown of my setup and the issues I’m encountering: Dockerfile_etcd: # Usa la imagen oficial de etcd como baseFROM quay.io/coreos/etcd:v3.5.0# Define el directorio de trabajoWORKDIR /etcd# Configura las variables de entorno para etcd, eliminando ETCD_LISTEN_CLIENT_URLSENV ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" \ ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379" \ ETCD_INITIAL_CLUSTER="etcd=http://etcd:2380" \ ETCD_INITIAL_CLUSTER_STATE="new" \ ETCD_DATA_DIR="/etcd-data" \ ETCD_NAME="etcd" \ ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd:2380"ENV ETCD_ENABLE_V2="true" \ ALLOW_NONE_AUTHENTICATION="yes" \ ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379" \ ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" \ ETCD_LOG_LEVEL="debug"# Exponer los puertos en los que etcd escuchaEXPOSE 2379 2380# Comando de inicio para etcdCMD ["etcd"] Dockerfile: FROM apache/apisix:latestUSER root# Create necessary directories for logs and set permissionsRUN mkdir -p /usr/local/apisix/logs && \ mkdir -p /usr/local/openresty/nginx/logs && \ mkdir -p /usr/local/openresty/nginx/client_body_temp && \ chown -R nobody:nogroup /usr/local/openresty/nginx /usr/local/apisix/logs /usr/local/openresty/nginx/logs /usr/local/openresty/nginx/client_body_temp && \ chmod -R 755 /usr/local/openresty/nginx/logs /usr/local/openresty/nginx/client_body_temp /usr/local/apisix/logs# Copy certificates and configuration filesCOPY ./conf/certs/rootCA.pem /usr/local/apisix/certs/ca-certificates.crtCOPY ./conf/certs/localhost.pem /usr/local/apisix/certs/localhost.pemCOPY ./conf/certs/localhost-key.pem /usr/local/apisix/certs/localhost-key.pemCOPY ./conf/config.yaml /usr/local/apisix/conf/config.yamlCOPY ./conf/routes.yaml /usr/local/apisix/conf/routes.yaml# Update certificatesRUN apt-get update && apt-get install -y ca-certificates && update-ca-certificatesRUN update-ca-certificates# Update log level for debug visibilityRUN sed -i's/log_level: warn/log_level: debug/' /usr/local/apisix/conf/config.yaml# Expose necessary portsEXPOSE 9080 9443 9180# Start APISIXCMD ["apisix","start","-c","/usr/local/apisix/conf/config.yaml","-v"] config. yaml : apisix: basic: enable:false config_center:"yaml" enable_dev_mode:false enable_reuseport:true enable_ipv6:true log_level: debug enable_http2:true show_upstream_status_in_response_header:false enable_server_tokens:true proxy_mode:"http" disable_sync_configuration_during_start:false node_listen: - 9080 - 9070 ssl: enable:true server_name: localhost listen: - ip:"0.0.0.0" port: 9443 enable_http3:true ssl_protocols: TLSv1.2 TLSv1.3 ssl_ciphers: DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES256-GCM-SHA384 ssl_session_tickets:false ssl_trusted_certificate: /etc/ssl/certs/ca-certificates.crt certs: cert: /usr/local/apisix/certs/localhost.pem key: /usr/local/apisix/certs/localhost-key.pem sni: localhosthttp: enable_access_log:true access_log: logs/access.lognginx_config: error_log_level:"info" hook_conf: enable:false name: hook_phase log_level: trace is_print_input_args:true is_print_return_value:true hook_phase: apisix: - http_access_phase - http_header_filter_phase - http_body_filter_phase - http_log_phasedocker ps -aroutes: http: radixtree_host_uri ssl: radixtree_sni path: /usr/local/apisix/conf/routes.yaml deployment: role: data_plane role_data_plane: config_provider: yaml#deployment:# role: traditional# role_traditional:# config_provider: etcd# admin:# enable_admin: false# admin_key:# - name: "admin"# key: "edd1c9f0985e76a2"# role: admin# allow_admin:# - 127.0.0.0/24# - 172.18.0.1# admin_listen:# ip: 0.0.0.0# port: 9180# etcd:# host:# - "http://etcd:2379"# prefix: /apisix# tls:# cert: /usr/local/apisix/certs/localhost.pem# key: /usr/local/apisix/certs/localhost-key.pem# sni: localhost plugin: - name: http-logger enable:true config: batch: 10 timeout: 5000 log_format:'{"client_ip": "$remote_addr", "method": "$request_method", "uri": "$request_uri", "status": "$status", "request_time": "$request_time", "body": "$request_body"}' log_level:"debug" log_target:"file" log_file:"/usr/local/apisix/logs/access.log" access_log:"/usr/local/apisix/logs/access.log" error_log:"/usr/local/apisix/logs/error.log" - name: cors enable:true - name: proxy-rewrite enable:true - name: jwt-auth enable:true - name: openid-connect enable:true - name: connection-limiting enable:true - name: redirect-https config: https_redirect_status_code: 301 routes. yaml: - uri: /api/v1/ name: resource-route upstream: nodes:"https://localhost:8081/api/v1/": 1 type: roundrobin methods: ["GET","POST"] plugins: - jwt-auth: key:"53cRe7k3y!zXy9*@1234Abc" algorithms: ["HS256"]- uri: /register name: register-user upstream: nodes:"https://localhost:8081/register": 1 type: roundrobin methods: ["POST","GET"] plugins: - cors: allow_origin:"https://localhost:9443, https://faasioflex.com:9443" allow_methods:"GET, POST" allow_headers:"Authorization, Content-Type" expose_headers:"X-faasioflex" allow_credentials:true max_age: 3600# Ruta para la autenticación de usuarios- uri: /login name: login-user upstream: nodes:"https://localhost:5557": 1# Redirige a Dex (por defecto, Dex está en localhost:5557) type: roundrobin methods: ["POST"] plugins: - openid-connect: client_id: backend# ID de cliente configurado en Dex client_secret: ZXhhbXBsZS1hcHAtc2VjcmV0# Secreto de cliente configurado en Dex discovery:"https://localhost:5557/.well-known/openid-configuration"# URL de configuración de OpenID Connect (Dex) token_endpoint_auth_method:"client_secret_basic"# Método de autenticación para el cliente scope: ["openid","profile","email","phone","nickname","name"]# Alcances solicitados- uri: /app/* name: your-api-route upstream: nodes:"https://localhost:5557": 1 type: roundrobin methods: ["GET","POST"] plugins: - openid-connect: client_id: backend# ID de cliente configurado en Dex client_secret: ZXhhbXBsZS1hcHAtc2VjcmV0# Secreto de cliente configurado en Dex discovery:"https://localhost:5557/.well-known/openid-configuration"# URL de descubrimiento de Dex token_endpoint_auth_method:"client_secret_basic"# Método de autenticación para el cliente scope: ["openid","profile","email","phone","nickname","name"]# Alcances que se solicita en el proveedor- uri: /functions/register name: register-functions upstream: nodes:"https://localhost:8081/functions/register": 1 type: roundrobin methods: ["POST"] plugins: - jwt-auth: key:"53cRe7k3y!zXy9*@1234Abc" algorithms: ["HS256"]- uri: /functions/activate name: activate-functions upstream: nodes:"https://localhost:8081/functions/activate": 1 type: roundrobin methods: ["POST"] plugins: - jwt-auth: key:"53cRe7k3y!zXy9*@1234Abc" algorithms: ["HS256"] - cors: allow_origin:"https://localhost:9443, https://faasioflex.com:9443" allow_methods:"GET, POST" allow_headers:"Authorization, Content-Type" expose_headers:"X-faasioflex" allow_credentials:true max_age: 3600- uri: /functions/execute name: execute-functions upstream: nodes:"https://localhost:8081/functions/execute": 1 type: roundrobin methods: ["POST"] plugins: - jwt-auth: key:"53cRe7k3y!zXy9*@1234Abc" algorithms: ["HS256"] - connection-limiting: conn_limit: 10# Limita a 10 conexiones simultáneas burst: 5# Permite un "pico" adicional de 5 conexiones default_conn_delay: 10# Si se alcanza el límite, se espera 10 ms antes de aceptar una nueva conexión - cors: allow_origin:"https://localhost:9443, https://faasioflex.com:9443" allow_methods:"GET, POST" allow_headers:"Authorization, Content-Type" expose_headers:"X-faasioflex" allow_credentials:true max_age: 3600- uri: /functions/delete name: execute-functions upstream: nodes:"https://localhost:8081/functions/delete": 1 type: roundrobin methods: ["POST"] plugins: - jwt-auth: key:"53cRe7k3y!zXy9*@1234Abc" algorithms: ["HS256"] - cors: allow_origin:"https://localhost:9443, https://faasioflex.com:9443" allow_methods:"GET, POST" allow_headers:"Authorization, Content-Type" expose_headers:"X-faasioflex" allow_credentials:true max_age: 3600- uri: /* name: catch-all-route upstream: nodes:"http://backend_service:8000": 1# Usa HTTP interno si APISIX maneja la conversión type: roundrobin plugins: redirect: http_to_https:true# Aplica solo cuando la solicitud entra por HTTP (9080) enable_websocket:true# Ruta HTTP /status- uri: /status name: status-http-route upstream: nodes:"https://localhost:8081": 1# Redirige a tu backend en https://localhost:8081 type: roundrobin methods: ["GET"] plugins: []# Sin plugins, solo proxy inverso# Ruta HTTPS /status (igual que la anterior)- uri: /status name: status-https-route upstream: nodes:"https://localhost:8081": 1# Redirige a tu backend en https://localhost:8081 type: roundrobin methods: ["GET"] plugins: []# Sin plugins, solo proxy inverso- uri: /heartgo name: status-route methods: ["GET"] upstream: type: roundrobin nodes:"https://localhost:9443": 1 plugins: - response-rewrite: body:'{"status": "ok"}' status_code: 200- uri: /heartgo name: status-route methods: ["GET"] upstream: type: roundrobin nodes:"http://localhost:9080": 1 plugins: - response-rewrite: body:'{"status": "ok"}' status_code: 200- uri: /hello name: hello-route upstream: type: roundrobin nodes: - host: google.com# Mantienes la respuesta de google para verificar port: 80 weight: 1 methods: ["GET"]# Responde a GET- uri: /heart name: heart-route upstream: type: roundrobin nodes:"127.0.0.1:8000": 1# Respondemos en localhost en el puerto 8000 methods: ["GET"]# Responde a GET- uri: /test name: id-test upstream: nodes:"${{HOST_IP}}:${{PORT}}": 1 type: roundrobin- uri: /id/1 name: id-route plugins: - response-rewrite: body:"hello\n"# Responde con el texto "hello\n" status_code: 200# Código 200 para indicar éxito methods: ["GET"]# Responde a GET script shesll to setup docker is: #!/bin/bash# Nombre de la imagen y del contenedorIMAGE_NAME="apisix"CONTAINER_NAME="apisix"ETCD_CONTAINER_NAME="etcd"NETWORK_NAME="faasioflexnetwork"ETCD_DOCKERFILE="Dockerfile_etcd"# Crear la red faasioflexnetwork si no existeif! docker network inspect$NETWORK_NAME>/dev/null2>&1;thenecho"La red$NETWORK_NAME no existe. Creando la red..." docker network create$NETWORK_NAMEelseecho"La red$NETWORK_NAME ya existe."fi# Eliminar contenedores detenidos, si existenSTOPPED_CONTAINERS=$(docker ps -a -q -f status=exited)if [-n"$STOPPED_CONTAINERS" ];then docker rm$STOPPED_CONTAINERSficontainer_id=$(docker ps -q -f name=$ETCD_CONTAINER_NAME)if [-z"$container_id" ];thenecho"Container ID is empty"elseecho"Container ID:$container_id"fi# Verificar si el contenedor etcd ya existeif [$(docker ps -a -q -f name=$ETCD_CONTAINER_NAME) ];thenecho"El contenedor$ETCD_CONTAINER_NAME ya existe. Deteniéndolo y eliminándolo..." docker stop$ETCD_CONTAINER_NAME docker rm$ETCD_CONTAINER_NAMEfi# Eliminar la imagen etcd si existeif [$(docker images -q$ETCD_CONTAINER_NAME) ];thenecho"La imagen de etcd ya existe. Eliminándola..." docker rmi -f$ETCD_CONTAINER_NAMEfi# Construir la imagen Docker para etcd desde el Dockerfile_etcdecho"Construyendo la imagen Docker para etcd desde$ETCD_DOCKERFILE..."docker build -f$ETCD_DOCKERFILE -t$ETCD_CONTAINER_NAME.# Verificar si la construcción de la imagen fue exitosaif [$?-ne 0 ];thenecho"Error al construir la imagen de etcd."exit 1fi# Ejecutar el contenedor de etcd (Esperar a que se inicie completamente)echo"Creando y ejecutando el contenedor de etcd..."docker run -d --name$ETCD_CONTAINER_NAME --network$NETWORK_NAME --publish 2379:2379$ETCD_CONTAINER_NAME /usr/local/bin/etcd# Esperar hasta que etcd esté completamente arrancado (puedes cambiar el tiempo de espera si es necesario)echo"Esperando a que etcd esté completamente en funcionamiento..."sleep 10# Aumenté el tiempo de espera para asegurarse de que etcd esté arrancado correctamente# Verificar que etcd está en ejecuciónETCD_STATUS=$(docker ps -q -f name=$ETCD_CONTAINER_NAME)if [-z"$ETCD_STATUS" ];thenecho"Error: El contenedor$ETCD_CONTAINER_NAME no se inició correctamente."exit 1elseecho"Contenedor$ETCD_CONTAINER_NAME en ejecución..."fi# Verificar si el contenedor apisix ya existeif [$(docker ps -a -q -f name=$CONTAINER_NAME) ];thenecho"El contenedor$CONTAINER_NAME ya existe. Deteniéndolo y eliminándolo..." docker stop$CONTAINER_NAME docker rm$CONTAINER_NAMEfi# Eliminar la imagen de APISIX si existeif [$(docker images -q$IMAGE_NAME) ];thenecho"La imagen$IMAGE_NAME ya existe. Eliminándola..." docker rmi -f$IMAGE_NAMEfi# Construir la imagen de APISIX desde el Dockerfileecho"Construyendo la imagen Docker para APISIX desde el Dockerfile..."docker build -t$IMAGE_NAME.# Verificar si la construcción de la imagen fue exitosaif [$?-ne 0 ];thenecho"Error al construir la imagen$IMAGE_NAME."exit 1fi# Crear y ejecutar el contenedor de APISIXecho"Creando y ejecutando el contenedor$CONTAINER_NAME..."echo"docker run -d -p 9080:9080 -p 9443:9443 -p 9180:9180 --name$CONTAINER_NAME --network$NETWORK_NAME$IMAGE_NAME"docker run -d -p 9080:9080 -p 9443:9443 -p 9180:9180 --name$CONTAINER_NAME --network$NETWORK_NAME$IMAGE_NAME# Verificar si el contenedor de APISIX se está ejecutandoCONTAINER_STATUS=$(docker ps -q -f name=$CONTAINER_NAME)if [-z"$CONTAINER_STATUS" ];thenecho"Error: El contenedor$CONTAINER_NAME no se inició correctamente."echo"Mostrando los logs del contenedor..." docker logs$CONTAINER_NAMEexit 1elseecho"Contenedor$CONTAINER_NAME en ejecución..." docker psfi# Verificar que los contenedores estén conectados a la redecho"Verificando que los contenedores estén conectados a la red$NETWORK_NAME..."docker network inspect$NETWORK_NAME| grep -A 10"Containers" Problem: Routes Not Being Executed: The routes defined in my routes.yaml are not being triggered. Specifically, requests to /api/v1/ do not get routed properly to the upstream services defined in routes.yaml. Things I’ve Tried: jogugil@PHOSKI:~/smartiaservices_projects/faasioflex/src$ curl -vhttp://127.0.0.1:9080/hello
< HTTP/1.1 404 Not Found
< HTTP/1.1 404 Not Found
I’ve been checking the logs but can’t see any errors pointing to the SSL issue or routing failure. |
BetaWas this translation helpful?Give feedback.