Apache&Nginx配置ssl证书

一、Apache配置ssl

Linux版本:CentOS Linux release 7.9.2009 (Core)

Apache版本:Apache/2.4.6 (CentOS)

1、安装Apache(使用默认yum源)

shell 复制代码
[root@10-35-1-25 ~]# yum -y install httpd

2、查Apache版本&启动Apache

shell 复制代码
[root@10-35-1-25 ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   May 30 2023 14:01:11
[root@10-35-1-25 ~]# systemctl start httpd

3、没有配置ssl时访问测试

4、安装mod_ssl

shell 复制代码
[root@10-35-1-25 ~]# yum -y install mod_ssl

安装成功以后httpd的配置文档下面会有一个ssl.conf文件

shell 复制代码
[root@10-35-1-25 ~]# ll /etc/httpd/conf.d/
total 28
-rw-r--r-- 1 root root 2926 May 30  2023 autoindex.conf
-rw-r--r-- 1 root root  366 May 30  2023 README
-rw-r--r-- 1 root root 9443 May 30  2023 ssl.conf
-rw-r--r-- 1 root root 1252 May 30  2023 userdir.conf
-rw-r--r-- 1 root root  824 May 30  2023 welcome.conf

5、上传ssl证书

shell 复制代码
[root@10-35-1-25 ~]# cd /etc/httpd/
[root@10-35-1-25 httpd]# mkdir certs
[root@10-35-1-25 httpd]# cd certs/
[root@10-35-1-25 certs]# ll
total 12
-rw-r--r-- 1 root root 1807 Feb  1 18:18 ca.crt
-rw-r--r-- 1 root root 1675 Feb  1 18:18 private.key
-rw-r--r-- 1 root root 2296 Feb  1 18:18 public.crt

6、修改ssl.conf文件&重启Apache

一般修改这三条参数就可以

shell 复制代码
[root@10-35-1-25 conf.d]# vim ssl.conf
SSLCertificateFile /etc/httpd/certs/public.crt
SSLCertificateKeyFile /etc/httpd/certs/private.key
SSLCertificateChainFile /etc/httpd/certs/ca.crt
[root@10-35-1-25 conf.d]# systemctl restart httpd.service

7、添加解析

xiaopy.info是申请证书时使用的域名,165.154.203.16是我Apache服务地址

8、访问测试

注:如果部署Apache服务的云服务器是国内大陆地区的,域名也没有备案的话,是不能绑定域名访问的。

二、Nginx配置ssl

Linux版本:CentOS Linux release 7.9.2009 (Core)

Nginx版本:nginx version: nginx/1.20.1

1、安装Nginx(使用默认yum源安装)

shell 复制代码
[root@10-7-180-181 ~]# yum -y install nginx
#如果默认yum源装不了nginx,就装一个额外的yum源
[root@10-7-180-181 ~]# yum install epel-release

2、查Nginx版本&启动Nginx

shell 复制代码
[root@10-7-180-181 ~]# nginx -v
nginx version: nginx/1.20.1
[root@10-7-180-181 ~]# systemctl start nginx

3、没有配置ssl时访问测试

4、上传ssl证书

shell 复制代码
[root@10-7-180-181 nginx]# mkdir certs
[root@10-7-180-181 certs]# pwd
/etc/nginx/certs
[root@10-7-180-181 certs]# ll
-rw-r--r-- 1 root root 1675 Feb  2 10:03 private.key
-rw-r--r-- 1 root root 4104 Feb  2 10:03 public.pem

5、修改ssl.conf文件&重启Apache

[root@10-7-180-181 nginx]# vim nginx.conf

第一段是nginx的http服务配置,第二段是nginx的https服务配置,将第一段代码注释掉,取消第二段代码的注释,然后修改ssl证书路径

我只改了这两条配置,将路径换成放置证书的证书路径就行

shell 复制代码
[root@10-7-180-181 nginx]# systemctl restart nginx.service

6、添加解析

xiaopy.info是申请证书时使用的域名,165.154.203.16是我Apache服务地址

7、访问测试

相关推荐
ZHOU西口9 小时前
微服务实战系列之玩转Docker(十五)
nginx·docker·微服务·云原生·swarm·docker swarm·dockerui
心勤则明11 小时前
Netty配置SSL证书加密
服务器·https·ssl
广东数字化转型12 小时前
SSL/TSL 总结
网络·网络协议·ssl
苹果醋313 小时前
react 路由 react-router/react-router-dom
运维·nginx
小徐敲java18 小时前
Windows本地制作java证书(与jeecgboot配置本地证书ssl问题)
java·windows·ssl
檀越剑指大厂18 小时前
开源多场景问答社区论坛Apache Answer本地部署并发布至公网使用
开源·apache
nvd1119 小时前
Java ETL - Apache Beam 简介
java·apache·etl
ps酷教程20 小时前
nginx进阶篇(二)
nginx
双普拉斯20 小时前
微信小程序点赞动画特效实现
nginx·微信小程序·notepad++
苏少朋21 小时前
Docker安装 ▎Docker详细讲解 ▎数据卷挂载 ▎Nginx安装理解
linux·nginx·docker·容器