2017-03-27 66 views
0

我正在嘗試使用NGINX設置SSL。
在更改爲443並添加文件路徑之前,它與端口80一起工作。SSL NGINX不會加載


我生成了csr和key。

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

我跟着this guidethis guide並已收到我的CRT和CA-束從Namecheap /科摩多。


我結合爲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不使用任何端口,那所有的例子。 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) 
+0

'nginx -t'的結果是什麼? –

回答

1

我找到了答案是刪除在證書,這是由添加了額外的換行符和空白科摩多。

所以這

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

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

貌似這個

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

還要注意的是複製粘貼到nano將在一行的末尾插入空格外。我用vim代替。