SSL 可用於用戶和 Web 服務器之間的安全通信。
證書在公共線路上對數據進行加密,因此可以免受黑客攻擊。
自己 發行的簽名證書可以免費使用,但不能在使用在信用卡 或是 PayPal 信息等機密數據的生產環境中使用。
Step 1 – 安裝 mod_ssl Package
為了設置 SSL 證書,請確保您的系統上安裝了 mod_ssl。 如果尚未安裝,請使用以下命令進行安裝。 此外,安裝 OpenSSL 包以創建證書。
dnf install mod_ssl openssl
Step 2 – 建立屬於自已發行的 認證中心
安裝 mod_ssl 和 OpenSSL 後,使用以下命令為您的域創建自簽名證書。(或是查看)
mkdir -p /etc/pki/tls/certs # 建立 目錄 cd /etc/pki/tls/certs # 轉進 路徑 (當前目錄) 建立 新的 SSL 證書 openssl req -x509 -nodes -newkey rsa:2048 -keyout first.com.key -out first.com.crt
openssl req -x509 -nodes -newkey rsa:2048 -days 1825 -keyout first.com.key -out first.com.crt
上述命令將在當前目錄中創建一個 ssl 密鑰文件 first.com.key 和一個證書文件 first.com.crt
Step 3 – 在 Apache 配置 SSL 虛擬主機 port 443
/etc/httpd/conf.d/dxqerp.com_ssl.conf # 建立 SSL 虛擬主機 環境設定 檔
<VirtualHost *:443>
ServerAdmin admin@first.com
DocumentRoot /var/www/first.com
ServerName first.com
ServerAlias www.first.com
<Directory /var/www/first.com>
#Allowoverride all ###Uncomment if required
</Directory>
SSLEngine on # 將此設置為“開”
SSLCertificateFile /etc/pki/tls/certs/first.com.crt # 設置 SSL 證書的位置
SSLCertificateKeyFile /etc/pki/tls/certs/first.com.key # 設置 SSL 私鑰證書的位置
ErrorLog logs/first.com_ssl-error.log
CustomLog logs/first.com_ssl-access.log combined
</VirtualHost>
Step 4 – 重啟 Apache
systemctl restart httpd
Step 5 – 使用 HTTPS 測試網站
https://www.first.com
最後,使用 https 在您喜歡的 Web 瀏覽器中打開您的站點。
它需要打開端口 443 才能使用 https 訪問站點.
由於我們使用的是自己發行的證書,您將在瀏覽器中收到一條警告消息。 您可以簡單地忽略此消息.
THE END
參考
How to Create and Install Self Signed Certificate in Apache