[精讚] [會員登入]
4298

[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 安裝 docker-composer 及使用 docker compose 是使用docker的利器,可以讓很多的指令用文檔的方式載入。

使用mutt發信(LINUX直接寄信) mutt是一個簡易的發送程式,學會他就不用每次telnet mail server 煩死人

[Centos8] 安裝phpMyAdmin Centos 8目前只能採用tarball安裝法

[Rocky9] 負載平衡器Haproxy安裝及設定 負載平衡器Haproxy安裝及設定,這次的範例是透過本機的一個埠背後連到數台資料庫伺服器。

[CentOS8] 1.安裝JULIA 安裝及開始使用 JULIA

[Linux] mongodb 初步--1/3 我使用mongo 的一些大小事:安裝及基本操作

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

[Freebsd] 使用 ADSL 撥接上網 Freebsd上要使用 ADSL 撥接上網,該如何設定?

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

為什麼要重造輪子? 什麼輪子?造什麼輪子?我為什麼要重造輪子?

[AS3] 我做的唯一一個Flash As3遊戲UFO INVADSION [AS3] 我做的唯一一個Flash As3遊戲,是第一個也是最後一個,後來就沒再寫as3,不過as3還滿好玩的。

[PHP] 檢查IP是否在某個網段內 mtachcidr 要檢查IP是否在某個網段內,要寫幾行?10行?5行? 不用,只要2行。以下是我寫的 code /** * matchCI