[精讚] [會員登入]
4194

[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

你可能感興趣的文章

[Centos7] 安裝php套件管理程式Composer+ Codeignioter3 很多人在用的套件管理程式 Composer+ Codeignioter3+ 指定安裝目錄

[CentOS6] 設定 sendmail Centos6上設定sendmail,基本上sendmail會設定多半是為了寄系統信和收垃圾信(喂!!?)

EXCEL+phpPgAdmin 使用phpPgAdmin 匯出資料 直接使用phpPgAmin下載資料的方法

[Linux] 使用tarball安裝下載PERL的tar檔模組 在Linux下,perl下載的pm模組,不使用cpan的安裝方法

[Rocky Linux9] 安裝docker+ docker compose+ apache+ maraidb+ php7 Rocky Linux(Centos9) 下安裝docker及docker compose

[Centos8][Rocky9] ffmpeg 安裝及使用,用ffmpef製作gif動畫 用ffmpef製作gif動畫,但是他的功能很強大,可以用指令來執行

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

HP SAS硬碟leds燈號說明 HP SAS硬碟leds燈號(hp g7/g6系統適用)說明

沒有非誰做不可的事,也沒有不可被取代的人 沒有非誰做不可的事,也沒有不可被取代的人

UTF-8 BOM (Byte Order Mark) 的問題 在 Michael Kaplan 那看到 Every character has a story #4: U+feff

Linux shell 的date表示法 linux下SHELL中的date表示法

[札記] 2016.7~12月札記 札記,只是札記