Apache版本2.4
安裝mod_ssl
yum install mod_ssl
建立文件夾,存放sslkey
mkdir /etc/httpd/ssl/
建立憑證檔
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt ...........................................................+++ ..............+++ writing new private key to '/etc/httpd/ssl/apache.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]:CHN string is too long, it needs to be less than 2 bytes long Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:HB Locality Name (eg, city) [Default City]:WH Organization Name (eg, company) [Default Company Ltd]:ZZ Organizational Unit Name (eg, section) []:ZZ Common Name (eg, your name or your server's hostname) []:WWW^H^[[3~^[[3~^[[3~^[[3~^[[3~^[[3~ Email Address []:webmaster@xxx.com
需要填寫一些內容,我隨便填的…
apache配置
/etc/httpd/conf.d/ssl.conf
我把這下面的內容復制到另外一個文件中配置的
<VirtualHost _default_:443> ***** </VirtualHost>
需要修改的幾項
DocumentRoot "/var/www/example.com/public_html" ServerName www.example.com:443 SSLCertificateFile /etc/httpd/ssl/apache.crt SSLCertificateKeyFile /etc/httpd/ssl/apache.key
重啟apache
systemctl restart httpd.service
通過以上步驟就能打開網頁的https鏈接了,但是此時的https瀏覽器會提示不安全的鏈接,那么就需要到阿里雲去申請一個CA證書,目前有免費版的CA證書,下面的鏈接是我發在百度的申請證書的教程,大家可以參考一下
https://jingyan.baidu.com/album/4b07be3c92836148b380f318.html
上一個效果圖
https變成綠色,說明證書生效!