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

相关推荐
sanx182 小时前
专业电竞体育数据与系统解决方案
前端·数据库·apache·数据库开发·时序数据库
光军oi5 小时前
全栈开发杂谈————关于websocket若干问题的大讨论
java·websocket·apache
NicolasCage15 小时前
解决苍穹外卖WebSocket连接失败的问题
nginx
维尔切18 小时前
Nginx 反向代理与负载均衡
运维·nginx·负载均衡
Justin_192 天前
nginx反向代理与缓存功能
运维·nginx
苹果醋32 天前
数据结构其一 线性表
java·运维·spring boot·mysql·nginx
java干货2 天前
我用Nginx做了负载均衡,还需要API网关吗?
运维·nginx·负载均衡
東雪蓮☆3 天前
LNMP 环境部署 WordPress
linux·运维·mysql·nginx·php
-dcr3 天前
22.Nginx 服务器 LNMP项目
运维·服务器·nginx·php·lnmp
東雪蓮☆3 天前
Docker 搭建 Nginx 并启用 HTTPS 具体部署流程
运维·nginx·docker