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

2022-06-22 15:16:22 浏览数 (1)

报错信息如下:

代码语言:javascript复制
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复制
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复制
[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复制
[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复制
[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

在这里插入图片描述

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

0 人点赞