Nginx中使用if指令加载多域名SSL证书报错的解决方法求助
Nginx中使用if指令加载多域名SSL证书报错的解决方法求助
各位大佬好,我最近碰到个Nginx配置的难题,想请教下大家:
我有两个域名 foo.com 和 bar.com,都是用Nginx来提供服务的。为了避免重复写配置代码,我打算把下面这段逻辑加到我的nginx.conf里:
[some code] if ($host = "foo.com") { ssl_certificate /etc/letsencrypt/live/foo.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/foo.com/privkey.pem; } if ($host = "bar.com") { ssl_certificate /etc/letsencrypt/live/bar.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/bar.com/privkey.pem; } [some code there]
结果Nginx检测配置的时候直接报错了,具体错误信息如下:
- Checking nginx' configuration ...
2023/07/18 20:10:15 [emerg] 2656#2656: "ssl_certificate" directive is not allowed here in /etc/nginx/nginx.conf:46
nginx: configuration file /etc/nginx/nginx.conf test failed
2023/07/18 20:10:15 [emerg] 2657#2657: "ssl_certificate" directive is not allowed here in /etc/nginx/nginx.conf:46
nginx: configuration file /etc/nginx/nginx.conf test failed
有没有大佬知道我该怎么调整配置才能实现这个需求呀?
备注:内容来源于stack exchange,提问作者somenxavier
相关产品推荐
相关产品推荐

