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、访问测试

相关推荐
苹果醋31 天前
element-ui源码阅读-样式
java·运维·spring boot·mysql·nginx
chen36731 天前
[Comake][D1][AI_AO][bf_ssl_demo]
网络·网络协议·ssl
向上的车轮1 天前
Actix Web 不是 Nginx:解析 Rust 应用服务器与传统 Web 服务器的本质区别
前端·nginx·rust·tomcat·appche
ljh_learn_from_base1 天前
【spring boot 使用apache poi 生成和处理word 文档】
java·spring boot·word·apache
SelectDB技术团队1 天前
Apache Doris 4.0 版本正式发布:全面升级 AI 与搜索能力,强化离线计算
人工智能·apache
探索宇宙真理.2 天前
Apache Tomcat RewriteValve目录遍历漏洞 | CVE-2025-55752 复现
java·经验分享·tomcat·apache·安全漏洞
lang201509282 天前
Apache Maven 项目的开发指南
java·maven·apache
摇滚侠2 天前
Nginx 与 F5 负载均衡的区别
nginx·负载均衡
微小冷2 天前
WireShark抓包http,解密https
http·https·edge·wireshark·ssl·解密
普普通通的南瓜2 天前
《国家安全法》下的 SSL 证书定位:网络数据加密的 “法定基石”
网络·php·ssl