多语言展示
当前在线:333今日阅读:61今日分享:18

在Nginx下部署SSL证书并重定向至HTTPS

SSL证书安装教程系列:如何在Nginx下部署SSL证书,并301重定向至HTTPS的教学步骤。
工具/原料
1

SSL证书

2

网站

3

Nginx

方法/步骤
1

下载 Nginx 版证书文件,解压以后可以看到一个 .key 文件和 .crt/.pem 文件

2

上传证书。把上面的 .key 文件和 .crt/.pem 文件上传到 /root 目录中,命名为 ssl.crt/ssl.pem 和 ssl.key

3

LNMP 一键安装包的 Nginx 配置在 /usr/local/nginx/conf/vhost/ 目录中,找到对应站点域名的配置文件。普通安装的 Nginx 配置文件在 /etc/nginx/nginx.conf。vi 命令进入修改。  将其修改为:    server {  listen 443;  server_name anxinssl.com www.anxinssl.com;# 修改为你的域名  ssl on;  root html;  index index.html index.htm;  ssl_certificate /root/ssl.pem;  ssl_certificate_key /root/ssl.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 / {  root html;  index index.html index.htm;  }  }

4

设置301重定向至HTTPS  server  {  listen 80;  server_name anxinssl.com www.anxinssl.com; # 修改为你的域名  rewrite ^/(.*) https://anxinssl.com/$1 permanent; # 如果你的网站是带 www 的,请在域名前添加 www  }  server  {  listen 443;  # ...... 其余配置同上  }END

注意事项

操作时记得将上面的域名改成自己的

推荐信息