milan
milan

Reputation: 2417

nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/api.domain.com/fullchain.pem"

I have generated fullchain.pem, privkey, ssl-dhparams locally and then saved to the nginx folder which I am copying from to docker nginx container. With the below setup, I am getting issue of nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/api.domain.com/fullchain.pem" failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/api.domain.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file

nginx.dockerfile

FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf
COPY fullchain.pem /etc/letsencrypt/live/api.domain.com/fullchain.pem
COPY privkey.pem /etc/letsencrypt/live/api.domain.com/privkey.pem
COPY options-ssl-nginx.conf /etc/letsencrypt/options-ssl-nginx.conf
COPY ssl-dhparams.pem /etc/letsencrypt/ssl-dhparams.pem

nginx.conf

http {
  include mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log combined;
  sendfile on;
  upstream app_server {
      server backend:8080 fail_timeout=0;
      # server APP_SERVER_2_IP;
  }

  server {
      listen 80 default_server;
      return 444;
  }

  server {
      listen 80;
      listen [::]:80;
      server_name api.domain.com;
      return 301 https://$server_name$request_uri;
  }

  server {
      server_name api.domain.com;

      client_max_body_size 4G;
      keepalive_timeout 5;
      location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
      }
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      # SSL
      ssl_certificate /etc/letsencrypt/live/api.domain.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/api.domain.com/privkey.pem;
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  }
}

why am I getting such issue?

UPDATE:

Sorry, I mismatched the name while copying my code. I have updated with it now.

Upvotes: 3

Views: 11463

Answers (1)

Amjad Hussain Syed
Amjad Hussain Syed

Reputation: 1040

seems like the path is wrong where you copied the cert is different that where you nginx configuration is pointing

COPY fullchain.pem /etc/letsencrypt/live/api.codolytics.com/fullchain.pem
COPY privkey.pem /etc/letsencrypt/live/api.codolytics.com/privkey.pem

now in nginx config its a different path

ssl_certificate /etc/letsencrypt/live/api.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.domain.com/privkey.pem;

Upvotes: 2

Related Questions