失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 如何在阿里云里申请并使用https证书SSL nginx下配置https证书

如何在阿里云里申请并使用https证书SSL nginx下配置https证书

时间:2022-02-04 15:11:35

相关推荐

如何在阿里云里申请并使用https证书SSL nginx下配置https证书

目前网站SSL证书基本已经普及了,很多站点基本都安装了SSL证书,而且目前不管是国内比较知名的云商家基本都提供免费的SSL证书。本次说的是阿里云提供的免费ssl证书。

废话不多说,直接上步骤:

1、登录阿里云控制台:/,点开产品服务->安全(云盾)->SSL证书(应用安全),如图:

2、进入之后点击右上角“购买证书”

3、选择品牌“Symantec”-->选择保护类型“1个域名”,这时候才会出现证书类型“免费型DV SSL”,选择这个免费的即可

4、选好之后点击购买即可

5、付完款之后返回证书控制台

6、点击申请,按照需求填写相关信息,然后点下一步,验证即可。提交审核后稍等几分钟就能通过审核了。

证书通过之后,接下来就是配置的事了。这里以nginx为例。

1、下载证书-->选择需要的服务器类型,这里以nginx为例。

2、下载好之后登陆服务器,打开nginx目录/usr/local/nginx,新建一个文件夹cert,讲证书解压后放进cert文件夹内。

3、配置nginx

server {listen 443 ssl;#listen 80;server_name www.zhudada.online;ssl_certificate/usr/local/nginx/cert/1631577_zhudada.online.pem;ssl_certificate_key /usr/local/nginx/cert/1631577_zhudada.online.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) {root /home/zhudada;index index.html;}# location / {# proxy_set_header Host $host;# proxy_pass http://47.107.99.77:80/index.html;# }}

4、重启nginx即可。

到这里需要注意几个问题:

1、Nginx如果未开启SSL模块,配置Https时提示错误。

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx

这是由于nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,解决步骤:

1:进入到源码包,如:

cd /root/nginx-1.15.6/

2:查看nginx原有的模块

/usr/local/nginx/sbin/nginx -V

3:查看configure arguments:后边有没有值,如果有,就复制下来。然后执行

./configure --原来有的模块(如果有的话) --with-http_ssl_module

4:执行make

make

5:关闭现在运行的Nginx服务器

/usr/local/nginx/sbin/nginx -s stop

提示:如果此时报错nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx,则先把有关https的配置注释再关闭。

6:执行

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

7:将新的 nginx 覆盖旧安装目录,执行

cp objs/nginx /usr/local/nginx/sbin/nginx

8:最后重启一下nginx即可

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

验证一下:输入/usr/local/nginx/sbin/nginx -V,这时会出现下面这种情况,说明已经成功了,可以用https访问你的网站了:

补充几点:

1、在上面第3步执行./configure的时候可能会出现以下报错:

./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl=<path> option.

解决方法:

Centos需要安装openssl-devel

Ubuntu则需要安装:sudo apt-get install libssl-dev

这时如果报错Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

解决方法:

第一种:

sudo vim /etc/resolv.conf

添加nameserver 8.8.8.8

第二种:

/etc/apt/sources.list 的内容换成

debhttp://old-/ubuntu/raringmainuniverserestrictedmultiverse

deb-srchttp://old-/ubuntu/raringmainuniverserestrictedmultiverse

debhttp://old-/ubuntu/raring-securitymainuniverserestrictedmultiverse

deb-srchttp://old-/ubuntu/raring-securitymainuniverserestrictedmultiverse

debhttp://old-/ubuntu/raring-updatesmainuniverserestrictedmultiverse

deb-srchttp://old-/ubuntu/raring-updatesmainuniverserestrictedmultiverse

debhttp://old-/ubuntu/raring-backportsmainrestricteduniversemultiverse

deb-srchttp://old-/ubuntu/raring-backportsmainrestricteduniversemultiverse

debhttp://old-/ubuntu/raring-proposedmainrestricteduniversemultiverse

deb-srchttp://old-/ubuntu/raring-proposedmainrestricteduniversemultiverse

然后sudo apt-get update一下就行了。

2、nginx配置输入网址后默认跳转至https站点

server {listen 80;server_name www.zhudada.online;rewrite ^(.*) https://$server_name$1 permanent;}server {listen 443 ssl;#listen 80;server_name www.zhudada.online;ssl_certificate/usr/local/nginx/cert/1631577_zhudada.online.pem;ssl_certificate_key /usr/local/nginx/cert/1631577_zhudada.online.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) {root /home/zhudada;index index.html;}# location / {# proxy_set_header Host $host;# proxy_pass http://47.107.99.77:80/index.html;# }}

到这里就结束了,如果安装配置过程中有任何问题,可以问我

qq: 412606846(微信同号)

如果觉得《如何在阿里云里申请并使用https证书SSL nginx下配置https证书》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。