首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >nginx开启ssl报错: [emerg] "server" directive is not allowed here ...

nginx开启ssl报错: [emerg] "server" directive is not allowed here ...

作者头像
非著名运维
发布于 2022-06-22 07:16:22
发布于 2022-06-22 07:16:22
3.7K00
代码可运行
举报
文章被收录于专栏:非著名运维非著名运维
运行总次数:0
代码可运行

报错信息如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] "server" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:106
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

使用的Nginx版本:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled

SSL配置如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
......
server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      cert.pem;
        ssl_certificate_key  cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

出现上面的问题,首先要排查ssl的模块有没有装,没有装则需要装上。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
...
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module

全部都检查了,没有问题,又从最基础的地方检查,后面原来是一个 } 的问题,删了就好了。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload

在这里插入图片描述

在这里插入图片描述 成功,所以细节还是挺重要的。❤

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 非著名运维 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档