Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网络篇 - https 免费证书申请 与 nginx 配置 #46

Open
HXWfromDJTU opened this issue Nov 23, 2020 · 0 comments
Open

网络篇 - https 免费证书申请 与 nginx 配置 #46

HXWfromDJTU opened this issue Nov 23, 2020 · 0 comments

Comments

@HXWfromDJTU
Copy link
Owner

前言

最近工作室的官网准备要上线了,也因为 https 的普遍使用,https 的原理读得多了,现在就来实操一次,为网站建立 https 证书吧。

申请流程

以腾讯云(免费)申请流程为例子

服务器配置ssl证书

nginx版本

1、下载证书包

请根据自己的服务器平台选择证书包


2、上传证书文件到服务器

使用scp等方法把证书放到服务器的conf目录,例如

$ scp xxxss.com_bundle.crt xxxss.com.key xxx.xxx.xxx.xx:/usr/local/nginx/conf/cert
3、(补充)安装 with-http_ssl_module 模块

在你安装nginx的目录下(这里要注意,不是/usr/local/nginx这个,一般会是nginx.10.x.x带版本号的那个,下面有一个configure可执行文件),用它来安装这个ssl模块

$ ./configure --with-http_ssl_module

然后在同样目录下执行make命令

$ make

然后备份之前的nginx,再将新配置的nginx覆盖掉旧的

$ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
$ cp objs/nginx /usr/local/nginx/sbin/nginx

哦对了~👆上面这个覆盖文件会需要你停止当前的nginx,避免你又查了,给你搬运过来了

$ nginx -s quit # 等待当前程序执行完后退出
$ nginx -s stop # 强制停了吧
添加配置
 server {
         listen 443;
         server_name xxxxxxxx.club;  # 此处为您证书绑定的域名。
         ssl on;   # 设置为on启用SSL功能。
         location / {
            proxy_pass http://nuxtSSR; # 前面配置的一个前端项目
         }
         # SSL 证书配置
         ssl_certificate cert/1_woniuhuafang.club_bundle.crt; # 您证书的文件名。
         ssl_certificate_key cert/2_woniuhuafang.club.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;   # 修改protocols。
         ssl_prefer_server_ciphers on;
      }

搞定之后检测一下语法没问题就重启happy吧

$ nginx -t # check 一下
$ nginx
完结阶段撒花

哇咔咔,小锁头被解开啦 🙃

错误回收站

1、ssl 前置标志符号不再推荐使用

[warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead

移除 ssl on配置,修改listen 443listen 443 ssl

@HXWfromDJTU HXWfromDJTU changed the title 计算机网络篇 - https 免费证书申请 与 nginx 配置 网络篇 - https 免费证书申请 与 nginx 配置 Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant