SSL NGINX无法加载

时间:2017-03-27 03:46:01

标签: linux ssl nginx server

我正在尝试使用NGINX设置SSL 在更改为443并添加文件路径之前,它与端口80一起使用。

我生成了csr和钥匙。

openssl req -new -newkey rsa:2048 -nodes -keyout example_com.key -out example_com.csr

我关注了this guidethis guide,并从Namecheap / Comodo收到了我的crt和ca-bundle。

我合并了NGINX的文件:

cat example_com.crt example_com.ca-bundle >> cert_chain.crt并加入/etc/nginx/ssl/

设置权限

sudo mkdir /etc/nginx/ssl
sudo chown -R root:root /etc/nginx/ssl
sudo chmod -R 600 /etc/nginx/ssl

sudo ls -l返回-rw------- 1 root root

站点-可用:

server {
    listen 443;

    ssl on;
    ssl_certificate /etc/nginx/ssl/cert_chain.crt;
    ssl_certificate_key /etc/nginx/ssl/example_com.key;
...

我的/etc/nginx/nginx.conf不使用任何端口,这些端口都在example.com网站中可用。

当我重新加载NGINX时:

sudo systemctl reload nginxsudo systemctl restart nginx

Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Sun 2017-03-26 22:16:54 UTC; 5h 8min ago
Process: 3998 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 3993 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=1/FAILURE)
Process: 3885 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 4000 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 3888 (code=exited, status=0/SUCCESS)

1 个答案:

答案 0 :(得分:1)

我发现答案是删除证书中额外的换行符和空格,这是由Comodo添加的。

这就是这个

...
-----END CERTIFICATE REQUEST-----

-----BEGIN CERTIFICATE REQUEST-----
...

看起来像这样

...
-----END CERTIFICATE REQUEST-----
-----BEGIN CERTIFICATE REQUEST-----
...

另请注意,将复制粘贴到nano中会在一行末尾插入额外的空格。我改用了vim。