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

相关推荐
itachi-uchiha12 小时前
命令行以TLS/SSL显式加密方式访问FTP服务器
服务器·网络协议·ssl
fydw_71512 小时前
生产环境中安装和配置 Nginx 以部署 Flask 应用的详细指南
运维·nginx·flask
xzh12 小时前
问题:Nginx client_body_temp_path 文件会删除吗,删除时机?
nginx·架构
dessler13 小时前
代理服务器-LVS的3种模式与调度算法
运维·服务器·网络·算法·nginx·tomcat·lvs
moppol14 小时前
SSL/TLS握手全流程拆解:从“Hello“到“安全通道“的每一个字节
网络·安全·ssl
itachi-uchiha17 小时前
使用vsftpd搭建FTP服务器(TLS/SSL显式加密)
运维·服务器·ssl
2501_9111212317 小时前
Nginx+Tomcat 负载均衡群集
nginx·tomcat·负载均衡
小鱼小鱼.oO1 天前
阿里云服务器安装nginx并配置前端资源路径(前后端部署到一台服务器并成功访问)
服务器·nginx·阿里云
广东数字化转型1 天前
nginx怎么使用nginx-rtmp-module模块实现直播间功能
linux·运维·nginx
Yungoal1 天前
php & apache构建 Web 服务器
服务器·php·apache