apache配置https

apache配置https

原文鏈接:https://www.cnblogs.com/ccccwork/p/6529367.html

1.安裝軟件
yum -y install httpd openssl mod_ssl

2.建立服務器祕鑰
mkdir /etc/httpd/crts #建立存放證書目錄
cd /etc/httpd/crts
openssl genrsa -out server.key 1024

3.建立服務器公鑰,隨便填寫提問的內容
openssl req -new -key server.key -out server.csr

4.建立服務器證書
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

5.修改配置文件
vim /etc/httpd/conf/httpd.conf
添加下面代碼到最後

RewriteEngine on #開啓地址重寫
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R] #訪問任何內容自動轉發到https

6.修改ssl.conf(443虛擬主機)
vim /etc/httpd/conf.d/ssl.conf

SSLCertificateKeyFile /etc/httpd/crts/server.key #私鑰位置
SSLCertificateFile /etc/httpd/crts/server.crt #證書位置

7.啓動服務
systemctl start httpd 或 service httpd start

8.直接在瀏覽器輸入ip即可訪問,提示不安全則 繼續訪問

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章