Nginx如果未开启SSL模块,配置Https时提示错误
原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上–with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经安装过了,怎么添加模块???
操作如下:
说明:我的nginx的安装目录是/usr/local/nginx这个目录(默认安装目录),我的源码包在/home/local/dyxx/download/nginx-1.14.2目录。
nginx: [emerg] the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:19
操作步骤
一步:切换到源码包:cd /home/local/dyxx/download/nginx-1.14.2
二步:查看nginx原有的模块 /usr/local/nginx/sbin/nginx -V
在configure arguments:后面显示的原有的configure参数如下:
三步:那么我们的新配置信息就应该这样写,运行下面的命令即可,等配置完。
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
四步:配置完成后,运行命令 make
【特别注意】这里不要进行make install,否则就是覆盖安装
五步:然后备份原有已安装好的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
五步:然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候【特别注意】这里nginx要停止状态)
cp ./objs/nginx /usr/local/nginx/sbin/
六步:然后启动nginx,仍可以通过命令查看是否已经加入成功
/usr/local/nginx/sbin/nginx -V
七步:最后启动nginx
定位:cd /usr/local/nginx/sbin/
停止:./nginx -s quit
启动:./nginx
Nginx 配置Http和Https共存
nginx.confhttps配置文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#网站配置----开始
server {
server_name xxoo.net www.xxoo.net xxoo.cn www.xxoo.cn;#这里可以配置多个域名已逗号空格我这里配置了4个(即用户可能输入你公司相关域名)
return 301 https://www.xxoo.com$request_uri;#这里的www.xxoo.com就是你公司的域名和**注意0**相同
}
server {
listen 80;
listen 443 ssl;
server_name www.xxoo.com;#**注意0**你的公司域名,最终浏览器地址栏看到的
ssl_certificate /home/local/xxoo/xxooCom/xxoo.com.pem;#这是你申请的ssl(Https证书地址)
ssl_certificate_key /home/local/xxoo/xxooCom/xxoo.com.key;#这是你申请的ssl(Https证书地址)
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://xxoo_web;#http://后面的xxoo_web与**注意1**处要相同
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-REAL-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
upstream xxoo_web{#**注意1**
server **服务器外网IP:端口**; #中间有个**:**
}
#网站配置-----结尾
}