[精讚] [會員登入]
4122

[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

你可能感興趣的文章

[postfix] open /etc/postfix/main.cf: Permission denied 等錯誤 遇到開啟 /etc/postfix/main.cf: Permission denied 等錯誤解決

[Centos7] 安裝 semanage (selinux工具程式) 安裝selinux的工具程式 semanage

[bc] linux 的計算機 bc 設定小數位數、計算π、次方根 linux 的計算機 bc 設定小數位數、計算π、次方根

Linux ext3 系統下刪除檔案救回全記錄 今天一個不小心,下了 rm 的指令,從此奮戰一個下午,終於把檔案救回來,以下是全記錄...

安裝SPHINX支援中文 新版本的 sphinx 和舊版不同,網路上很多範例和教學是不能用的。此文是安裝和設定方法分享

[Centos8] linux 上的Base64加解密指令 在linux上很方便的指令可以加解密 base64

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

對物品的感情 這個議題很奇怪,可是大部分的人都會有,物品是死的,壞了就淘汰,出新的就被替換。為何會有情感?

分享還是炫耀? 是分享還是炫耀,取決於對方的的心態和你的心態...

[Mysql/MariaDB] 查看資料庫所占空間 查看資料庫在磁碟中所占空間

[SIP] OPENSER LINUX版本安裝全記錄 [SIP] OPENSER LINUX版本安裝全記錄

踩地雷公式解 由數學排列法演算出踩地雷公式解,主要有三種解:唯一解、歸納解、猜測