[精讚] [會員登入]
3597

[Centos7] HTTPS/SSL憑證的SELINUX設置

把申請來的憑證檔放到指定的位置後,沒辦法啟動,怎麼辦?

分享此文連結 //n.sfs.tw/12047

分享連結 [Centos7] HTTPS/SSL憑證的SELINUX設置@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2021-07-20 15:53:48 最後編修
2017-11-20 01:23:42 By 張○○
 

自動目錄

要讓網頁支援SSL,先決條件,你得申請或購買SSL的憑證,取回的憑證會有以下檔案。

放置憑證檔

/etc/pki/tls/certs/

  root.cer,  server.cer, server-chain.cer(不一定有中繼憑證)

/etc/pki/tls/private/

  privatekey.key

安裝 mod_ssl

檢查 mod_ssl

rpm -qa | grep mod_ssl

如果沒有顯示任何東囑,請安裝

dnf install mod_ssl

 

編輯 ssl.conf

# vi /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/pki/tls/certs/server.cer
SSLCertificateKeyFile /etc/pki/tls/private/privatekey.key
SSLCACertificateFile /etc/pki/tls/certs/root.cer

# 中繼視情況加上,無則省略
SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt

完整ssl.conf 範列

Listen 443 https
<VirtualHost _default_:443>
    SSLEngine on
    DocumentRoot /home/ddns/public_html
    ServerName ddnss.tc.edu.tw
    <Directory "/home/ddns/public_html">
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>
  SSLCertificateFile /etc/pki/tls/certs/your_certificate.crt
  SSLCertificateKeyFile /etc/pki/tls/private/your_private.key
  SSLCACertificateFile /etc/pki/tls/certs/your_ca_certificate.crt
#  SSLCertificateChainFile /etc/pki/tls/certs/your_cert_chain.crt
</VirtualHost>

SELINUX 設置

上面的所有憑證檔案,你都得給他們 cert_t 的type

# chcon -u system_u -t cert_t *.cer
# chcon -u system_u -t cert_t privatekey.key

如果沒設置SELINUX,重啟APACHE後,會出現這樣的錯誤,竟然系統說找不到檔案??

11月 20 00:55:40 example.com httpd[21960]: AH00526: Syntax error on line 102 of /etc/httpd/conf.d/ssl.conf:
11月 20 00:55:40 example.com httpd[21960]: SSLCertificateFile: file '/etc/pki/tls/certs/server.cer' does not exist or is empty

防火牆

#  firewall-cmd --zone=public --add-port=443/tcp --permanent

HTTP指定到HTTPS

這個放在你原本的80埠設定裡

<VirtualHost *:80>
...
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

重啟 APACHE

 

相關連結

[HTTPS] Ubuntu +SSL +正式的CA 設定

[SSL] 免費的SSL憑證(三個月)

[Centos7] SSL自簽憑證+APACHE+Selinux

 

END

你可能感興趣的文章

移除ssl 私鑰的密碼 現在用ssl產生私鑰會需要設定密碼,但是私鑰有密碼,啟動apache會失敗。

[Centos7] 把帳號新增移除具有root權限等級的sudoer 把帳號新增或移除具有root權限等級的sudoer

[CENTOS7] 使用 logrotate 來整理mongo日誌檔 解決 mongo 的日誌檔不斷長大的問題

[Centos8] 安裝及設定docker docker 是一個應用程式的容器,相對於vm是作業系統的容器。此篇整理基本安裝及設定。

[Oracle9] 查看磁碟檔案類型、掛載和uuid linux 如何查看掛載的磁碟類型?此文做個整理。

[CENTOS7/8] 安裝中文字型 如何在Centos7上安裝和移除中文字型?

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

Smarty安裝 smarty 是著名的樣版引擎,非常的好用,用多了突然發現拿掉smarty反而不會寫php了,以下是安裝過程..

外匯課程經驗 有天遇到某個朋友的正妹朋友,說她有個很棒的外匯投資課程,要我們去聽,只收場地費200大洋。她又說續效最差一個月也有1%,誰還在苦哈哈上班?

[CodeIgniter 3] 資料庫的使用方法整理1/2 --Select的使用 [CodeIgniter 3] 資料庫的使用方法整理:Select的使用

海棉寶寶超泡杯演奏的sweet victory 章魚哥和海棉寶寶在超泡杯的演奏歌曲