登录  /  注册
首页 > 运维 > linux运维 > 正文
如何在Apache中创建和安装自签名证书
不言
发布: 2019-03-30 15:15:28
原创
2776人浏览过

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
登录后复制

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

以上就是如何在Apache中创建和安装自签名证书的详细内容,更多请关注php中文网其它相关文章!

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学