1. 在linux系統中,創建名爲localhost.cnf 的文件,文件內容如下
[dn]
CN=localhost
[req]
distinguished_name = dn
[EXT]
subjectAltName=DNS:localhost
keyUsage=digitalSignature
extendedKeyUsage=serverAuth
2. 執行如下命令
openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config localhost.cnf
3. 將localhost.crt和localhost.key拷貝到conf.d目錄
修改在apache的配置文件目錄conf.d 下修改ssl.conf,
LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost _default_:443>
DocumentRoot "/data/htdocs" #修改爲自己的網站目錄
Servername localhost
LogLevel warn
SSLEngine on
SSLCertificateFile "conf.d/localhost.crt"
SSLCertificateKeyFile "conf.d/localhost.key"
</VirtualHost>