Nginx解决配置SSL证书报错:nginx: [emerg] unknown directive “ssl_certificate1“ in /usr/local/nginx/conf/ngi...

前段时间自己尝试了下Nginx的反向代理, 将请求转发到Tomcat上; 应公司项目需要就自己研究了下配置添加证书, 实现https的请求; 我的证书是从阿里云买的免费的证书, 按照阿里云的提示, 将nginx.conf文件配置了下,配置如下:

 # HTTPS server
    server {
 
      listen 443;
      server_name www.test.com; #自己的域名
      ssl on;
      root html;
      index index.html index.htm;
      #这里的.pem/.key文件替换成自己对应的文件名
      ssl_certificate   cert/xxxxxx.pem;
      ssl_certificate_key  cert/xxxxx.key;
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_prefer_server_ciphers on;
      location / {
          #代理的目标地址
          proxy_pass http://127.0.0.1:8000;
          }
    }

开始以为按照这个配置, 就可以监听443端口了, 什么事都不是那么顺利,在objs文件夹中使用

./nginx -t

来检查配置文件是否合法时候, 总是报错误


  1. nginx: [emerg] unknown directive "ssl_certificate1" in /usr/local/nginx/conf/nginx.conf:107

  2. nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

这里的107行就是下面这个配置

ssl_certificate   

非常郁闷, 检查了好久, 以为是路径配置错误; 后来自己也百度了下, 才发现是nginx没有装-----ssl模块;

下面是排除问题的方法:

1.在nginx的安装目录执行

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

2.在nginx安装目录执行

make

千万不要make install 否则会覆盖现有的nginx

OK ~!! 这样事情就能完美解决, 再也不会有明明配置很正确的报错啦~!

你可能感兴趣的:(Linux,项目开发实用工具,nginx,ssl,https)