上傳SSL證書(shū)到服務(wù)器是一項(xiàng)重要的任務(wù),它有助于保護(hù)您的網(wǎng)站和用戶(hù)的數(shù)據(jù),以下是如何將SSL證書(shū)上傳到服務(wù)器的詳細(xì)步驟:
1. 準(zhǔn)備SSL證書(shū)文件
在開(kāi)始之前,確保您已經(jīng)獲得了SSL證書(shū),通常,您會(huì)收到一個(gè)包含以下文件的ZIP壓縮包:
證書(shū)文件(通常以.crt
或.pem
為擴(kuò)展名)
私鑰文件(通常以.key
為擴(kuò)展名)
可選:中間證書(shū)(通常以.cabundle
或.intermediates.pem
為擴(kuò)展名)
2. 登錄到服務(wù)器
使用SSH客戶(hù)端(如PuTTY或終端)登錄到您的服務(wù)器,確保您具有管理員權(quán)限,以便能夠安裝SSL證書(shū)。
3. 導(dǎo)航到網(wǎng)站目錄
在服務(wù)器上,導(dǎo)航到托管您網(wǎng)站的目錄,這通常是/var/www/html
或/home/your_username/public_html
。
4. 創(chuàng)建SSL證書(shū)文件夾
在網(wǎng)站目錄下創(chuàng)建一個(gè)名為ssl
的新文件夾。
mkdir /path/to/your/website/ssl
5. 上傳SSL證書(shū)文件
使用FTP客戶(hù)端(如FileZilla或WinSCP)將您的SSL證書(shū)文件上傳到剛剛創(chuàng)建的ssl
文件夾,確保將證書(shū)文件、私鑰文件和可選的中間證書(shū)文件都上傳到該文件夾。
6. 配置Web服務(wù)器
根據(jù)您的Web服務(wù)器類(lèi)型(Apache或Nginx),按照以下步驟配置SSL證書(shū)。
6.1 Apache
在Apache的配置文件中,找到與您的網(wǎng)站相關(guān)的虛擬主機(jī)配置,通常,這位于/etc/httpd/conf/extra/httpdvhosts.conf
或/etc/apache2/sitesavailable/your_domain.conf
。
在虛擬主機(jī)配置中,添加以下內(nèi)容:
<VirtualHost *:80> ServerName your_domain.com Redirect permanent / https://your_domain.com/ </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName your_domain.com DocumentRoot /path/to/your/website SSLEngine on SSLCertificateFile /path/to/your/website/ssl/your_domain.crt SSLCertificateKeyFile /path/to/your/website/ssl/your_private.key SSLCertificateChainFile /path/to/your/website/ssl/DigiCertCA.crt <Directory "/path/to/your/website"> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> </IfModule>
替換your_domain.com
、/path/to/your/website
和證書(shū)文件路徑為實(shí)際值。
6.2 Nginx
在Nginx的配置文件中,找到與您的網(wǎng)站相關(guān)的服務(wù)器塊配置,通常,這位于/etc/nginx/sitesavailable/your_domain.conf
。
在服務(wù)器塊配置中,添加以下內(nèi)容:
server { listen 80; server_name your_domain.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name your_domain.com; root /path/to/your/website; ssl_certificate /path/to/your/website/ssl/your_domain.crt; ssl_certificate_key /path/to/your/website/ssl/your_private.key; ssl_trusted_certificate /path/to/your/website/ssl/DigiCertCA.crt; location / { try_files $uri $uri/ =404; } }
替換your_domain.com
、/path/to/your/website
和證書(shū)文件路徑為實(shí)際值。
7. 重啟Web服務(wù)器
根據(jù)您使用的Web服務(wù)器類(lèi)型,重啟相應(yīng)的服務(wù)以使更改生效。
7.1 Apache
sudo systemctl restart httpd
或
sudo service apache2 restart
7.2 Nginx
sudo systemctl restart nginx
或
sudo service nginx restart
8. 測(cè)試SSL證書(shū)
使用瀏覽器訪(fǎng)問(wèn)您的網(wǎng)站,檢查地址欄中是否顯示安全鎖圖標(biāo),您可以使用在線(xiàn)SSL檢查工具(如SSL Labs的SSL Server Test)來(lái)驗(yàn)證您的SSL證書(shū)是否正確安裝。