Linux 系统下 ngnix 使用 HTTPS 协议启动报错:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.c
报错原因:
未安装 SSL 模块 --ngx_http_ssl_module
解决方法:
1. 先查看 nginx 原有的模块:/usr/local/nginx/sbin/nginx -V (或./nginx -V) 在 configure arguments: 后面显示的参数如下:--prefix=/usr/local/nginx --with-http_stub_status_module , 则代表未安装 SSL 模块
2. 那么安装好的参数应该是这样:
3. 接下来输入命令:
yum -y install openssl openssl-devel (非必须)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 运行命令即可,
4. 等配置完成后, 运行命令: make 这里不要进行 make install, 否则就是覆盖安装
5. 然后备份原有已安装好的 nginx: cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
6. 然后将刚刚编译好的 nginx 覆盖掉原有的 nginx(这个时候 nginx 要停止状态):cp ./objs/nginx /usr/local/nginx/sbin/ 然后启动 nginx, 仍可以通过命令查看是否已经加入成功 /usr/local/nginx/sbin/nginx -V
最后附上完整安装 nginx 方法:
1. 安装 nginx 前, 我们首先要确保系统安装了 g++,gcc,openssl-devel,pcre-devel 和 zlib-devel 软件,
- yum install gcc-c++
- yum -y install zlib zlib-devel pcre pcre-devel
- yum -y install openssl openssl-devel
2. 切换到需要安装 nginx 的目录, 我这里在 / usr/local/ , 然后下载 nginx: wget https://nginx.org/download/nginx-1.11.3.tar.gz
## 如果已安装 nginx, 则 remove 掉 yum remove nginx
3. 解压下载好的 nginx 包: tar -zxvf nginx-1.11.3.tar.gz
4. 开始安装:/usr/local/nginx-1.11.3 -- 是 nginx 的解压后的源码包
执行安装: ./configure --prefix=/usr/local/nginx
安装 https 认证模块 (上文未安装这个导致使用 https 协议保存):./configure --with-http_ssl_module
再执行: make
最后执行: make install
查看安装成功:
进入安装后的包 :
最后进入 sbin/nginx 目录,./nginx 启动即可
5. 配置 nginx https 代理请求:
- server {
- server_name yuming.cn; ## 需要代理的域名
- listen 443 ssl;
- ssl on; ## 如果安装的是新版本下不需要
- ssl_certificate certPath/cert.pem; ##SSL 证书地址
- ssl_certificate_key certPath/cert.key;##SSL 证书公钥
- ssl_session_timeout 3m;## 超时时间
- 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://120.xx.xx.xx:9006; ## 这里写需要转发的项目地址
- }
- }
来源: https://www.cnblogs.com/laifw/p/11193537.html