Nginx - setting up SSL with existing .crt, .key and CA.pem files

放肆的年华 提交于 2020-07-10 12:20:03

问题


I have a .crt, .key and CA.pem files that were generated like this.

These certs are kind of project-wide, and they work when firing up a webpack-dev-server server on HTTPS like:

devServer: {
  https: {
    key: fs.readFileSync('/path/to/example.com.key'),
    cert: fs.readFileSync('/path/to/examle.com.crt'),
    ca: fs.readFileSync('/path/to/CA.pem'),
  }
}

Now I need to setup an Nginx server using these 3 files, but I've been trying with no luck. Here's my config:

server {
    listen       3000;

    ssl_certificate certs/example.com.crt;
    ssl_certificate_key certs/example.com.key;

    # where does the CA.pem file go??
}

The result of this is Chrome giving me a

This site can’t provide a secure connection 
example.com sent an invalid response.
ERR_SSL_PROTOCOL_ERROR

Nginx logs show random hex characters:

172.18.0.1 - - [14/Dec/2018:18:01:55 +0000] "\x16\x03\x01\x00\xDD\x01\x00\x00\xD9\x03\x03\xAB\xE1\xB3\x1F\xCE\x02\x02\xC5}q\xDFgd\xF1`\xC1m\x8E\x99\xCE' \x98\xDF\xDEEg\x8Fm\xED\x9F\xB1\x00\x00\x1C" 400 166 "-" "-" "-" 0.001 -

Any ideas what could I be doing wrong?


回答1:


You need to concatenate your certificate with CA for nginx:

cp example.com.crt example.com.fullchain.pem
cat CA.pem >> example.com.fullchain.pem

and use this file in nginx config:

ssl_certificate certs/example.com.fullchain.pem;


来源:https://stackoverflow.com/questions/53784876/nginx-setting-up-ssl-with-existing-crt-key-and-ca-pem-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!