【问题标题】:SSL NGINX Wont LoadSSL NGINX 无法加载
【发布时间】:2017-08-19 15:25:00
【问题描述】:

我正在尝试使用 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)

【问题讨论】:

  • nginx -t 的结果是什么?

标签: linux ssl nginx server


【解决方案1】:

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

这样

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

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

看起来像这样

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

另请注意,复制粘贴到 nano 会在行尾插入额外的空格。我用 vim 代替。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 2016-08-02
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    相关资源
    最近更新 更多