Nginx 安装 SSL 配置 HTTPS
1、安装基础支持包
yum -y install openssl openssl-devel
2、下载nginx源码包,并解压
./configure --with-http_ssl_module
make
make install
3、配置
server { listen 443 ssl; # 域名,多个以空格分开 server_name xxx.com xxx.xxx.com; # ssl证书地址 ssl_certificate /usr/local/nginx/cert/ssl.pem; ssl_certificate_key /usr/local/nginx/cert/ssl.key; # ssl验证相关配置 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 / { root html; index index.html index.htm; } }
将 http 重定向 https。
server { listen 80; server_name xxx.com xxx.xxx.com; return 301 https://$server_name$request_uri; }
查看 nginx 是否安装 http_ssl_module 模块
nginx -V