ssl 模块支持
./sbin/nginx -s reloadnginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module
查看Nginx安装的模块
/usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.14.2built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)configure arguments: --prefix=/usr/local/nginx
在configure arguments:后面显示的原有的configure参数,不支持ssl模块,需要增加ssl 模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
查看当前Nginx是否在运行
# ps -ef|grep nginxroot 1270 1 0 4月10 ? 00:00:00 nginx: master process sbin/nginxnobody 3762 1270 0 10:56 ? 00:00:00 nginx: worker processroot 4104 4082 0 15:29 pts/1 00:00:00 grep --color=auto nginx
备份原有已安装好的nginx二进制文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
重新编译新的Nginx
#cd ~/nginx-1.14.2#./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module# make# cp ./objs/nginx /usr/local/nginx/sbin/ -rfcp:是否覆盖"/usr/local/nginx/sbin/nginx"? y
热部署
# kill -USR2 1270[root@aliyun sbin]# ps -ef|grep nginxroot 1270 1 0 4月10 ? 00:00:00 nginx: master process sbin/nginxnobody 3762 1270 0 10:56 ? 00:00:00 nginx: worker processroot 6676 1270 0 15:43 ? 00:00:00 nginx: master process sbin/nginxnobody 6677 6676 0 15:43 ? 00:00:00 nginx: worker processroot 6679 4082 0 15:44 pts/1 00:00:00 grep --color=auto nginx
关闭原先的work 保留master 实现回滚
kill -WINCH 1270
本地制作证书
1. 生成服务器端的私钥 (key 文件)$openssl genrsa -out server.key 10242. 生成服务器端证书签名请求文件 (csr 文件);$ openssl req -new -key server.key -out server.csr...Country Name:CN------------ 证书持有者所在国家State or Province Name:BJ-- 证书持有者所在州或省份(可省略不填)Locality Name:BJ----------- 证书持有者所在城市(可省略不填)Organization Name:SC------- 证书持有者所属组织或公司Organizational Unit Name:.- 证书持有者所属部门(可省略不填)Common Name :ceshi.com----- 域名Email Address:------------- 邮箱(可省略不填)A challenge password:------ 直接回车An optional company name:-- 直接回车3. 生成证书文件 (crt 文件)$ openssl x509 -req -days 1000 -in server.csr -signkey server.key -out server.crt
申请ssl证书
阿里云免费ssl证书
腾讯云免费ssl证书
server {listen 443 ssl;server_name baxiang.club www.baxiang.club;ssl_certificate 1_www.baxiang.club_bundle.crt;ssl_certificate_key 2_www.baxiang.club.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;}}
修改配置完成后,重启 nginx 服务
nginx -s reload //使配置生效
配置 http 强制跳转 https
在 nginx 配置文件中的 server 区域添加如下内容
if ($scheme = 'http') {rewrite ^(.*)$ https://$host$uri;}
