作者简介:大家好,我是思无邪,2024 毕业生,某厂 Go 开发工程师.。

我的网站:https://www.yishanicode.top/ ,持续更新,希望对你有帮助。

如果文章或网站知识点有错误的地方,烦请指正!和大家一起学习,一起进步

如果感觉博主的文章还不错的话,请三连支持一下博主哦

在阿里云租用了一个云服务器,已经开启了 DNS,但是还没有配置 ssl 证书,访问的时候由于是 http 访问,因此安全性没有保障。

而且没有开启 https 会有浏览器提示不安全、搜索引擎不索引等弊端。这里开启了,今天记录一下过程。

已有的物料:

  • 阿里云已经配置好的 http 服务,使用 NGINX 代理
  • 新申请的 ssl 证书

一共就两步:

  1. 上传 ssl 证书到服务器中
  2. 修改 NGINX 配置并重启

上传 ssl 证书到服务器中

在阿里云服务器中下载好 NGINX 对应的 ssl 证书文件后上传到服务器。

我的上传地址:

修改 NGINX 配置并重启

这里要先看一下自己的 NGINX 是否开启了 ssl,需要保证开启

由于我用的 centos,然后用的 yum 命令安装,应该是默认开启了。

如果是自己编译的话可能会没有开启,需要重新编译开启。

查看方式:nginx -V

[root@iZbp1eg8yt9s4umtpxez9jZ cert]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

确认 ssl 开启之后需要修改对应的配置文件绑定证书的位置。

如果忘记了自己用的哪个配置文件可以使用nginx -t来查看。

[root@iZbp1eg8yt9s4umtpxez9jZ cert]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

输出显示我这里的文件是:/etc/nginx/nginx.conf

命令行使用 vim /etc/nginx/nginx.conf 即可修改文件。

[root@iZbp1eg8yt9s4umtpxez9jZ cert]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/ user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096; include /etc/nginx/mime.types;
default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /yishanicode/src/.vuepress/dist;
index index.html;
}
error_page 404 /404.html;
location = /404.html {
root /yishanicode/src/.vuepress/dist;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 这里是新增的 gzip 配置
gzip on;
gzip_min_length 1k;
gzip_comp_level 6;
gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;
} ##这里之前是注释掉的 start
# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.yishanicode.top;
root /usr/share/nginx/html;
# 路径需要修改成自己对应的配置
ssl_certificate "cert/yishanicode.pem";
ssl_certificate_key "cert/yishanicode.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block. ## 这里的配置直接抄上面sever80的配置就行(http的配置)
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /yishanicode/src/.vuepress/dist;
index index.html;
}
error_page 404 /404.html;
location = /404.html {
root /yishanicode/src/.vuepress/dist;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 这里是新增的 gzip 配置
gzip on;
gzip_min_length 1k;
gzip_comp_level 6;
gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml; } ##这里之前是注释掉的 end
}

到这里保存文件,使用 nginx -s reload 重启即可。

当然也可以再使用 netstat -napt|grep 443 查看 nginx 是否开始监听 443 端口。

现在不妨访问网站看一下:首页已经可以使用https成功访问了~~~

本文由博客一文多发平台 OpenWrite 发布!

阿里云开启ssl证书过程记录 NGINX的更多相关文章

  1. 阿里云域名ssl证书导入aws负载均衡使用

    一 .原因 由于公司战略需求,需要将阿里云的服务器迁移到aws,在迁移过程中,我们需要使用的是aws的负载均衡,可以在EC2的控制台 负载平衡位找到负载均衡.根据业务需求我们使用的是应用程序负载均衡器 ...

  2. 申请安装阿里云免费SSL证书

    微信小程序已经全面要求使用HTTPS服务了,还有苹果商店也是,所以,实现网站HTTPS已经很有必要.要实现HTTPS就需要一个SSL证书,证书大部分都很贵,不过也有一些免费的证书服务供个人开发者使用. ...

  3. 阿里云申请ssl证书

    申请证书(本文以阿里云服务器为背景,申请证书也以阿里云域名申请证书来作为实例) (1)登陆阿里云服务器,初次配置的用户,不建议直接搜索‘ssl证书’进行购买,因为这样购买后证书与域名对应的引导性并不强 ...

  4. 阿里云配置ssl证书

    一.申请证书和下载证书(阿里云申请) 二.在nginx服务器上配置ssl证书 1.检查服务器是否安装openssl 2.在nginx conf 文件夹创建 cret 文件,放置证书 [root@web ...

  5. 阿里云服务器配置SSL证书成功开启Https(记录趟过的各种坑)

    环境: 阿里云云服务器    Windows Server 2008 标准版 SP2 中文版(趁1212优惠买的一年的水货配置) 阿里云购买的域名(已备案.已解析) 服务器:phpstudy:php5 ...

  6. 阿里云-免费SSL证书申请及验证步骤

    1.登录阿里云管理控制台,在搜索栏输入ssl,选择第一个SSL证书控制台回车即可 2.点击右上角的购买证书 3.选择购买最后一个品牌 4.选择增强型OV SSL 5.选中后会自动弹出免费型DV SSL ...

  7. 在阿里云购买SSL证书,让网站支持HTTPS

    SSL简介 引自:https://baike.baidu.com/item/ssl/320778?fr=aladdin SSL SSL(Secure Sockets Layer 安全套接层),及其继任 ...

  8. 阿里云部署SSL证书详解

    http://mp.weixin.qq.com/s/NV7Zad4DVEgzG2GCHYJVLw 查找中间证书 为了确保兼容到所有浏览器,我们必须在阿里云上部署中间证书,如果不部署证书,虽然安装过程可 ...

  9. 阿里云免费SSL证书申请与安装使用(IIS7)

    准备: 阿里云已完成备案的域名一个 第一步:免费SSL证书申请 登陆阿里云平台,在域名控制台下,选择你的域名,点击“SSL”证书,如图所示 再跳转后的页面,选择“单域名免费证书”,并补全域名,非二级域 ...

  10. 【转】阿里云免费SSL证书申请与安装使用(IIS7)

    阅读目录 准备: 第一步:免费SSL证书申请 第二步:证书导入 第三步:分配服务器证书 最后一步:访问测试 回到顶部 准备: 阿里云已完成备案的域名一个 回到顶部 第一步:免费SSL证书申请 登陆阿里 ...

随机推荐

  1. 利用AI运动识别插件,可以实现那些应用场景?

    「Ai运动识别」小程序插件已经推出一年有余,迭代了近十几个版本,收获了各类应用场景的众多用户,今天我们就带您深度解析一下插件的各类可应用场景,帮助已集成开发者进行一步拓宽应用场景,帮助有需求的开发者快 ...

  2. JAVA反序列化学习-前置知识(基于ysoserial)

    本人在学习Java反序列化中,发现网上大多都是自己分析一些逻辑内容,导致可能每一个版本的payload都不相同,对于学习时并不友好,所以我在学习了cc链之后,准备总结一下cc链中的内容,并以ysose ...

  3. (系列十二)Vue3+.Net8实现用户登录(超详细登录文档)

    说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...

  4. highcharts中的仪表盘样式

    仪表盘的样式如下: 是双表盘展示 左边的图中minorTickInterval的值为null,右边的minorTickInterval的值为"auto" 左边的图中lineColo ...

  5. MySQL之配置my.cnf

    1)可以实现直接使用mysql登录MySQL,需要添加配置文件, 进行客户端配置即可 ~/.my.cnf [client] port = 3306 socket = /var/lib/mysql/my ...

  6. 2018-2019 9th BSUIR Open Programming Championship

    I. Equal Mod Segments \(1 \leq n \leq 1e5\) \(1 \leq a_i \leq 3e5\) 题解:ST表 + 扫描线 + 二维偏序 取模存在一个不错的性质: ...

  7. (系列十三)Vue3+Echarts搭建超好看的系统面板

    说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...

  8. Qt QLabel 文字自适应大小

    直接上代码: void Adjust(QLabel * lb) { QFont font(lb->font()); while(1) { QFontMetrics fontMetrics(fon ...

  9. node 使用 pm2-logrotate 分割pm2日志 && 停止 pm2-logroatate

    使用pm2-logrotate 解决pm2日志体积过大,进行分割 什么是pm2-logrotate? pm2-logrotate 是一个pm2的插件,可以对pm2日志进行管理,所以它的运行需要依靠pm ...

  10. mysql 创建字段createtime 自动添加时间

    1. 创建createtime字段 类型选为timestamp 2.  添加默认值 CURRENT_TIMESTAMP