让 nginx 监听 443 并提供 https 服务 这样配置为啥不行呢?

2020-08-03 23:09:30 +08:00
 Newyorkcity
server {
    listen              443 ssl;
    server_name         xxx.yyy;
    ssl_certificate     /etc/nginx/ssl/1_xxx.yyy_bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/2_xxx.yyy.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    root /var/www/html;

    index index.html;

    location / {
		try_files $uri $uri/ =404;
	}
}

http://nginx.org/en/docs/http/configuring_https_servers.html nginx 配置 https 官网给的前面半段的配置项,后面的是从 /etc/nginx/sites-avaliable/default 文件抄的。

上面这段代码单独地写在 /etc/nginx/sites-avaliable/https 中,然后用了一个软连接 ln -s /etc/nginx/sites-avaliable/https /etc/nginx/sites-enable/ ,就像 debian 社区里介绍安装和使用 nginx 一样。我安装也是看这个的,debian 9,用 apt-get 装的。。

netstat -nlp 看不到监听 443 的进程。

谢谢解惑

1907 次点击
所在节点    问与答
9 条回复
momocraft
2020-08-03 23:13:05 +08:00
確定被 include 了嗎?
serco
2020-08-03 23:13:05 +08:00
nginx 启动了吗?修改配置后 reload 了吗?
myd
2020-08-03 23:13:16 +08:00
启动 nginx 的时候没报错吗
Newyorkcity
2020-08-03 23:14:53 +08:00
@momocraft 应该 include,nginx.conf 我没改动过,`include /etc/nginx/sites-enabled/*;` 这句话也好好的放在文件里


@serco systemctl restart nginx 了
@myd 没有 nginx -t 表示配置没什么问题 systemctl restart nginx 是什么输出都没有
dtgxx
2020-08-03 23:20:14 +08:00
目录不一样,你 include 的是`include /etc/nginx/sites-enabled/*, 你的路径是 /etc/nginx/sites-enable/ 少个 d
shc
2020-08-03 23:32:54 +08:00
`nginx -t`测试一下配置文件有没有检测通过
Newyorkcity
2020-08-03 23:35:10 +08:00
@dtgxx 感谢,不过只是我在发帖的时候少打了,真实文件位置的话是有那个 d 的,不过还是感谢你的细心查看和热心


@shc

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

nginx -t 的结果如上,应该没问题吧。。
gstqc
2020-08-04 00:01:07 +08:00
nginx -T
可以打印所有配置
Newyorkcity
2020-08-04 00:21:21 +08:00
@gstqc 感谢 从打印的结果上来看我配置的 server 确实没有被引入。我查了一下发现原来是我在设置软连接的时候使用了相对路径导致的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/695375

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX