如何在Apache中创建和安装自签名证书教程-学派吧

SSL对于用户和Web服务器之间的安全通信很有用。证书在公共线路上传输时对数据进行加密,这样它就不会受到黑客的攻击。自签名证书是免费使用的,但不在生产环境中使用,例如使用信用卡、Paypal信息的机密数据。本篇文章将介绍关于在Linux系统上的Apache服务器中创建和安装自签名证书。

如何在Apache中创建和安装自签名证书教程-学派吧

步骤1:安装mod_ssl包

要设置SSL证书,请确保在系统上安装了mod_ssl。如果尚未安装,需要使用以下命令进行安装。另外,安装openssl包来创建证书。

$ sudo apt-get install openssl          # Debian based systems 
$ sudo yum install mod_ssl openssl      # Redhat / CentOS systems 
$ sudo dnf install mod_ssl openssl      # Fedora 22+ systems

步骤2:创建自签名证书

安装mod_ssl和openssl后,使用以下命令为你的域创建一个自签名证书。

$ sudo mkdir -p /etc/pki/tls/certs
$ sudo cd /etc/pki/tls/certs

现在创建SSL证书

$ sudo openssl req -x509 -nodes -newkey rsa:2048 -keyout example.com.key -out example.com.crt

输出

Generating a 2048 bit RSA private key
....................................+++
...................................+++
writing new private key to 'example.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]: IN
State or Province Name (full name) []: Delhi
Locality Name (eg, city) [Default City]: Delhi
Organization Name (eg, company) [Default Company Ltd]: TecAdmin
Organizational Unit Name (eg, section) []: blog
Common Name (eg, your name or your server's hostname) []: www.example.com
Email Address []: admin@example.com

上面的命令将在当前目录中创建一个ssl密钥文件example.com.key和一个证书文件example.com.crt。

步骤3:在Apache中安装自签名证书

现在拥有了自签名SSL证书和密钥文件。接下来编辑Apache SSL配置文件并按照以下指令进行编辑/更新。

Apache虚拟主机配置:

<VirtualHost _default_:443>
    ServerAdmin admin@example.com
    ServerName www.example.com
    ServerAlias example.com

    DocumentRoot /var/www/html

    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/example.com.crt
    SSLCertificateKeyFile /etc/pki/tls/certs/example.com.key
</VirtualHost>

步骤4:重启Apache

如果上面的命令没有显示任何错误,请重新启动Apache服务。

$ sudo systemctl restart apache2       # Debian based systems   
$ sudo systemctl restart httpd         # Redhat based systems

步骤5:使用https测试网站

最后,使用https在你的Web浏览器中打开你的站点。它需要打开端口443才能使用HTTPS访问站点。

 https://www.example.com

当我们使用自签名证书时,你将在浏览器中收到一条警告消息,忽略此消息就可以了。

 

主题测试文章,只做测试使用。发布者:云大使,转转请注明出处:https://www.xp8.net/server/3634.html

(0)
打赏 微信扫一扫 微信扫一扫
云大使的头像云大使
上一篇 2019年5月7日 下午9:55
下一篇 2019年5月7日 下午9:55

相关推荐

  • Windows快速排查系统是否被黑

    一、Windows [v_blue]1.存在隐藏用户或异常用户[/v_blue] 以Windows为例,右键计算机 -> 管理 -> 查看本地用户和组,如果用户或用户组带有$符号,说明该用户/用户组被隐藏,很有可能被黑了。如下截图[v_blue]2.异常进程[/v_blue] 通过任务管理器查看是否存在异常进程,比如phpstudy被黑后可能存在12345.…

    2018年4月2日
    2.2K00
  • 学派吧-在linux下安装python3的过程教程-linux教程

    本篇文章主要介绍了在centos7下安装python3的步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 环境搭建 准备工具: centos7:mirror.bit.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso virtuslvox:www.virtualbo…

    服务器运维 2018年12月14日
    2.0K00
  • 学派吧-详解linux 删除换行符的方法-linux教程

    这篇文章主要介绍了linux 删除换行符的方法小结,需要的朋友可以参考下 今天需要删除文件里面的换行符,比如有一个文件a.txt: 1,2,34,5,61,2,34,5,61,2,34,5,61,2,34,5,61,2,34,5,6 1、使用vim删除换行符 vim输入命令:%s/\n//g 2、使用sed命令,例如 sed ':t;N;s/\n/…

    服务器运维 2019年1月1日
    2.0K00
  • 介绍linux磁盘冗余阵列实例教程分析-学派吧

    如果您有服务器咨询问题、购买问题、可以联系我们客服 7271895 690624 商祺云-阿里代理、景安代理、西部代理 RAID防止硬盘物理损坏以及增加存储设备的吞吐量,RAID常见的组合有0、1、5、和10 RAID0:至少需要两块硬盘,可以有效提高硬盘的性能和吞吐量,但没有数据的冗余和错误修复能力 将多块硬盘通过硬件或软件的方式串联在一起,成为一个大的卷…

    服务器运维 2019年1月17日
    2.2K00
  • Nginx利用fastcgi_cache缓存php页面教程

    前言 配置 1. 在nginx的主配置文件 2. 站点配置 3.验证 4. 遇到问题 前言 fastcgi_cache是一个nginx的插件,用于缓存fastcgi接口的执行结果,例如缓存php的执行结果。特别是php网站的首页与一些非交互页面,利用fastcgi_cache可以大幅度提升访问速度,并且降低php的执行压力。 配置 1. 在nginx的主配置…

    服务器运维 2018年10月16日
    3.4K00

发表回复

登录后才能评论
联系我们

联系我们

18838889666

在线咨询: QQ交谈

邮件:xinyun@88.com

工作时间:周一至周五,9:30-18:30,节假日休息

添加微信
添加微信
分享本页
返回顶部
---------官方优惠叠加渠道折扣:通过我们购买腾讯云/阿里云,价格更低,服务更优。更有专业配置指导与服务。微信同步:18838889666----