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

相关推荐
MickeyCV29 分钟前
Nginx学习笔记:常用命令&端口占用报错解决&Nginx核心配置文件解读
前端·nginx
网安Ruler42 分钟前
靶场之路-Kioptix Level-1 mod_ssl 缓冲区溢出漏洞
网络·网络协议·网络安全·ssl
web182854825124 小时前
nginx 部署前端vue项目
前端·vue.js·nginx
零星_AagT1 天前
Apache-CC6链审计笔记
java·笔记·apache·代码审计
fajianchen1 天前
什么是HTTP/2协议?NGINX如何支持HTTP/2并提升网站性能?
nginx·http
m0_748248771 天前
在 Ubuntu 上安装 Nginx 的详细指南
nginx·ubuntu·postgresql
anddddoooo2 天前
域内证书维权
服务器·网络·网络协议·安全·网络安全·https·ssl
Nerd Nirvana2 天前
OpenSSL crt & key (生成一套用于TLS双向认证的证书密钥)
linux·ssl·shell·认证·加密·tls·oepnssl
若云止水2 天前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_os_init 函数
运维·nginx
m0_512744642 天前
Nginx(详解以及如何使用)
运维·服务器·nginx