Tell nginx to silently ignore missing files

Viewed 1321

I am looking for a way to tell nginx to use a particular certificate if available, otherwise ignore silently (i.e. don't crash)

server {
    listen      443 ssl;
    server_name myapp.io;

    ssl_certificate           /path/to/my/certificate.cer;
    ssl_certificate_key       /path/to/my/certificate.key;
}

Currently this crashes with

2018/10/29 12:25:16 [emerg] 18978#0: BIO_new_file("path/to/my/certificate.cer") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('path/to/my/certificate.cer','r') error:2006D080:BIO routines:BIO_new_file:no such file)

What I am trying to achieve is have the server running, such that certbot can generate a certificate for me and subsequently add it, but currently the server crashes when it cannot find a file, which to me is fragile.

1 Answers

I don't think it is possible to achieve what you want. Instead generate & use self signed certificates for ssl or configure nginx for port 80 only until you get CA signed certs.

Related