在CentOS系統上安裝SSL證書的步驟如下:
sudo yum install httpd
sudo yum install nginx
sudo yum install mod_ssl
Certbot是一個自動獲取和配置SSL證書的工具,特別適合使用Let’s Encrypt免費證書的情況。
sudo yum install certbot python2-certbot-apache # 對于Apache
# 或者
sudo yum install certbot python2-certbot-nginx # 對于Nginx
sudo certbot --apache # 對于Apache
# 或者
sudo certbot --nginx # 對于Nginx
Certbot會自動修改Web服務器的配置文件以啟用SSL。
sudo systemctl restart httpd # 對于Apache
# 或者
sudo systemctl restart nginx # 對于Nginx
如果選擇手動安裝SSL證書,可以按照以下步驟進行:
tar -xvf your_certificate.tar
cd your_certificate
編輯/etc/httpd/conf/httpd.conf
或相應的虛擬主機配置文件,添加以下內容:
<VirtualHost *:443>
ServerName yourdomain.com
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
SSLCertificateChainFile /path/to/your/chainfile.pem
DocumentRoot /var/www/html
# 其他配置...
</VirtualHost>
重啟Apache:
sudo systemctl restart httpd
編輯/etc/nginx/nginx.conf
或相應的配置文件,添加以下內容:
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /path/to/your/certificate.crt;
ssl_certificate_key /path/to/your/private.key;
ssl_trusted_certificate /path/to/your/chainfile.pem;
# 其他配置...
}
重啟Nginx:
sudo systemctl restart nginx
使用瀏覽器訪問你的域名(例如https://yourdomain.com
),確保瀏覽器顯示安全的連接(通常會顯示一個鎖圖標)。