在搭建Web服務(wù)器的過程中,SSL證書的配置是至關(guān)重要的一步,它能夠保證你的網(wǎng)站在傳輸數(shù)據(jù)時的安全性,防止數(shù)據(jù)被竊取或者篡改,本文將以CentOS 6和CentOS 7為例,詳細(xì)介紹如何在這兩個操作系統(tǒng)上配置SSL證書。
CentOS 6上搭建web服務(wù)器的SSL證書配置
1、安裝HTTPS模塊
在CentOS 6上,我們需要首先安裝mod_ssl模塊,它是Apache HTTP服務(wù)器的一個擴(kuò)展,用于支持SSL和TLS協(xié)議。
yum install mod_ssl mod_ssldevel
2、生成SSL證書
我們可以使用OpenSSL工具來生成自簽名的SSL證書,我們需要創(chuàng)建一個私鑰文件:
openssl genrsa out /etc/pki/tls/private/localhost.key 2048
我們使用這個私鑰文件來生成一個證書簽名請求(CSR):
openssl req new key /etc/pki/tls/private/localhost.key out /etc/pki/tls/certs/localhost.csr
我們使用私鑰和CSR來生成一個自簽名的SSL證書:
openssl x509 req days 365 in /etc/pki/tls/certs/localhost.csr signkey /etc/pki/tls/private/localhost.key out /etc/pki/tls/certs/localhost.crt
3、配置Apache服務(wù)器
我們需要修改Apache的配置文件httpd.conf,啟用mod_ssl模塊,并指定SSL證書和私鑰的路徑。
LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpdssl.conf SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
4、重啟Apache服務(wù)器
我們需要重啟Apache服務(wù)器,使配置生效:
service httpd restart
CentOS 7上搭建web服務(wù)器的SSL證書配置
1、安裝HTTPS模塊
在CentOS 7上,我們同樣需要首先安裝mod_ssl模塊,可以使用以下命令進(jìn)行安裝:
yum install mod_ssl openssl firewalld y
2、生成SSL證書
在CentOS 7上,我們可以使用Let’s Encrypt來自動獲取和更新SSL證書,我們需要安裝Certbot工具:
yum install epelrelease y && yum install certbot python2certbotnginx y && yum clean all && systemctl start certbot && systemctl enable certbot
我們可以使用Certbot來生成和配置SSL證書:
sudo certbot nginx d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv0 server https://acmev02.api.letsencrypt.org/directory d example.com d www.example.com preferredchallenges http w /var/www/example.com/public_html n secureport=443 standalone m example@example.com d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal vvvvvvvvvvvvvvvvvvvvvvvvvvv0 server https://acmestagingv02.api.letsencrypt.org/directory d example.com d www.example.com preferredchallenges http w /var/www/example.com/public_html n secureport=443 standalone m example@example.com d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal vvv0 server https://acmestagingv02.api.letsencrypt.org/directory d example.com d www.example.com preferredchallenges http w /var/www/example.com/public_html n secureport=443 standalone m example@example.com d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal v0 server https://acmestagingv02.api.letsencrypt.org/directory d example.com d www.example.com preferredchallenges http w /var/www/example.com/public_html n secureport=443 standalone m example@example.com d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal h 0.0.0.0:443 apache d example.com d www.example.com preferredchallenges http w /var/www/example.com/public_html n secureport=443 standalone m example@example.com d example.com d www.example.com redirect registerunsafelywithoutemail agreetos stapleocsp renewby default forcerenewal c /etc/letsencrypt/live/example.com/fullchain.pem k /etc/letsencrypt