暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

让ubuntu使用apache2支持ssl

智慧大数据 2020-08-20
214

让ubuntu使用apache2支持ssl

Key是私用秘钥,通常是RSA算法,
Csr是证书请求文件,用于申请证书,
Crt是CA认证后的证书文件,签署人用自己的key给你签署凭证

一、生成KEY和CRT文件

  • 1、apache2启用 ssl 模块

a2enmod ssl

a2enmod proxy #让apache2支持代理



    1. 安装openssl

apt-get -y install openssl



    1. 创建CA签名(不使用密码去除-des3选项)

openssl genrsa -des3 -out server.key 1024


输入密码,确认密码,记住密码,后面会用到


    1. 创建CSR(Certificate Signing Request)

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


需要依次输入国家,地区,组织,email
最重要的是有一个common name,可以写你的名字或者域名,如果为了https申请,这个必须和域名吻合,否则会引发浏览器警报。
输出内容为:
Enter pass phrase for root.key: ← 输入前面创建的密码
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]: ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []: ← 电子邮箱
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入

  • 5、备份服务器密钥文件

cp server.key server.key.org


  • 6、去除文件口令

openssl rsa -in server.key.org -out server.key


  • 7、自己生成证书文件server.crt

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



二、apache2配置

  • 1、复制证书到目录

mkdir /etc/apache2/ssl

cp server.crt /etc/apache2/ssl/certs

cp server.key /etc/apache2/ssl/private


  • 2、软连接

//查看软连接是否正常

ll /etc/apache2/mods-enabled/ssl/ssl.*

//新建一个软连接

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


  • 3、更新ssl配置

vim etc/apache2/sites-enabled/default-ssl.conf

# 修改web目录

DocumentRoot var/www/html/public

# 开启ssl

SSLEngine on

# A self-signed (snakeoil) certificate can be created by installing

# the ssl-cert package. See

# usr/share/doc/apache2/README.Debian.gz for more info.

# If both key and certificate are stored in the same file, only the

# SSLCertificateFile directive is needed.

# 修改下面注释的内容为不注释的内容

# SSLCertificateFile etc/ssl/certs/ssl-cert-snakeoil.pem

# SSLCertificateKeyFile etc/ssl/private/ssl-cert-snakeoil.key

SSLCertificateFile /etc/apache2/ssl/certs

SSLCertificateKeyFile /etc/apache2/ssl/private


  • 4、重新加载apache2

/etc/init.d/apache2 force-reload

/etc/init.d/apache2 restart

netstat -nltp|grep 443



文章转载自智慧大数据,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论