用 nginx 配置 https 时,需要配置 443 端口、私钥路径、证书路径。会报错如下:
root@VM-173-231-ubuntu:~# nginx -t
nginx: [emerg] BIO_new_file("/usr/local/nginx/conf/1_yculcy.cn_bundle.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/nginx/conf/1_yculcy.cn_bundle.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed
如下图:
报错提示配置文件有错误,找不多私钥和证书。
最终发现,无论windows还是linux,只要写绝对路径,就会报错。
所以:
在 windows 下,将证书文件等放到 nginx/conf/ 目录下,配置文件中,不用加路径;
在 linux 下,可以将证书文件等放到 nginx.conf 同级目录下,不加路径即可,或者也可以放到 nginx/conf/ 目录下,可以加相对路径。