docker compose –> nginx cannot load certificate

I am very new to Docker and containers.
I am using docker-compose to start up my application. I keep getting this error:

2024/07/19 17:05:54 [emerg] 1#1: cannot load certificate "/etc/nginx/certs/certificate.pem": PEM_read_bio_X509_AUX() failed (SSL: error:0480006C:PEM routines::no start line:Expecting: TRUSTED CERTIFICATE)

My docker-compose.yml looks like this for this reverse proxy server:

:
    image: 
    build:
        context: ./
        dockerfile: Dockerfile.nginx
    volumes:
      - $SSL_CERT_PATH:/etc/nginx/certx/certificate.pem
      - $SSL_KEY_PATH:/etc/nginx/certs/certificate.key
      - $LOG_ROOT:
    ports:
      -"80:80"
      -"443:443"
    depends_on:
      - 
      - 
      - 

When I echo my $SSL_CERT_PATH I get the path that I would expect where the cert is located on my Mac.

Here is my Dockerfile.nginx:

FROM containers.
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

I have tried manually changing my .pem file to start with
---BEGIN TRUSTED CERTIFICATE---
as opposed to
---BEGIN CERTIFICATE---
as this was the solution here. But I continue to get the same error.

Here is part of my default.conf:

server {
    listen 80 default_server;
    server_name_;
    server_tokens off;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    server_name_;
    server_tokens off;

    ssl_certificate /etc/nginx/certs/certificate.pem;
    ssl_certificate_key /etc/nginx/certs/certificate.key;

If I comment out the last 6 lines, I do not get the error, so my container runs and I can exec into it. (But I need to use SSL!) When I bash into the container with docker exec -it sh I can navigate to /etc/nginx/certs. Turns out certificate.pem and certificate.key are empty directories and not files. Shouldn’t Docker be mounting them as files?

Thanks for the help!

Read more here: Source link