Loading... ## 从HTTP到HTTPS的过程记录 ### 申请证书: 我用的是在腾讯云的网站申请的证书(<span class="external-link"><a class="no-external-link" href="https://console.cloud.tencent.com/ssl" target="_blank"><i data-feather="external-link"></i>腾讯云证书</a></span>,亚洲诚信的证书现在是免费的,当然别的网站也行。) 申请证书之后他会要求你进行一些操作来验证网站属于你,只需要按着提示做就好,很简单方便。 这里插一句:我选择的文件验证,然后我误教程里面的文件内容放在验证文件里面了,所以一直等都没下来,别人HTTPS都可以访问了我的还没验证通过... ### 下载证书: 验证通过后就可以下载证书了,腾讯云的根据四种比较主流的web服务程序有不同的文件,根据实际情况选用。 有一个*****.crt & ******.key,确认有这两个文件就可以了。 ### 上传证书以及Nginx配置: 我们要把证书文件上传至我们自己的服务器,我使用的是Nginx,那么就选择Nginx版本上传到自己制定的目录,后面配置nginx会需要这个目录。 下面就是修改配置文件,建议先备份目前可用的配置文件,方便及时回退。 ``` # Port 80 Config Redirect port 80 to 443 server { listen 80; server_name blog.yelvlab.cn; rewrite ^(.*) https://$server_name$1 permanent; } 上面这部分是是把80端口的访问导向443的HTTPS访问。 # Port 443 Config server { # Server_name Config server_name blog.yelvlab.cn; # Enable HTTP/2.0 listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; # SSL Config 配置SSL相关 ssl_certificate /root/nginx_ssl/1_blog.yelvlab.cn_bundle.crt; CRT文件 ssl_certificate_key /root/nginx_ssl/2_blog.yelvlab.cn.key; KEY文件 ssl_prefer_server_ciphers on; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;这里是加密方式,我这里填写的是腾讯云给的实例里面的。 # Website directory 网站目录 root /var/www/html; # Add index.php to the list if you are using PHP 网站首页文件 index index.php index.html index.htm index.nginx-debian.html; 这里是配置CGI相关使nginx可以处理PHP # pass the PHP scripts to FastCGI server listening on /run/php/php7.0-fpm.sock location ~* \.php$ { fastcgi_index index.php; fastcgi_pass unix:/run/php/php7.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } } ``` 修改完配置文件可以`nginx -t`进行查看 配置文件最上面端口导向部分参考[nginx从http跳转到https](https://www.cnblogs.com/nuccch/p/7681592.html) Last modification:October 12, 2020 © Allow specification reprint Like 0 If you think my article is useful to you, please feel free to appreciate