Ubuntu 16.04 Apache https设置及SSL免费证书安装

前端之家收集整理的这篇文章主要介绍了Ubuntu 16.04 Apache https设置及SSL免费证书安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、开启SSL模块

a2enmod ssl

这条命令相当于

sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled

如果没有a2enmod指令,也可直接在apache2.conf中设置SSL模块加载:

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

创建第三方CA机构签署证书

向第三方提交一个“生成证书请求文件(CSR)”

openssl genrsa -des3 -out server.key 1024

-des3选项能对私钥进行加密,采用此选项会在后续的设置中提示你输入密码(只是加密私钥,https访问时不需要这个密码)

这样会在当前目录下生成server.key私钥文件

生成请求文件CSR(Certificate Signing Request)

openssl req -new -key server.key -out server.csr

这里还需提供一系列信息,比如:

Country Name
Province Name
Common Name
Email

其中Common Name最好用域名,否则https访问时会出现证书不一致的情况

自己签发证书

openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

3650表示证书有效期10年

复制到SSL目录

cp server.crt /etc/ssl/certs
cp server.key /etc/ssl/private

修改apache配置文件

ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
vim /etc/apache2/sites-enabled/default-ssl.conf

在DocumentRoot中加入内容

SSLEngine On  
SSLOptions +StrictRequire  
SSLCertificateFile /etc/ssl/certs/server.crt  
SSLCertificateKeyFile /etc/ssl/private/server.key

重启apache即可

原文链接:https://www.f2er.com/ubuntu/350683.html

猜你在找的Ubuntu相关文章