安裝httpd

yum -y install httpd

刪除歡迎頁面

rm -f /etc/httpd/conf.d/welcome.conf

編輯httpd.conf

vi /etc/httpd/conf/httpd.conf
86行 ServerAdmin root@cheng.ddns.net
95行 ServerName cheng.ddns.net:80
151行 AllowOverride All
164行 DirectoryIndex index.html index.cgi index.php
在最底下新增一行
ServerTokens Prod

重啟服務並讓服務開機啟動

systemctl start httpd
systemctl enable httpd

設定防火牆規則並重新載入

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

建立一個網頁測試(隨便輸入點什麼都可以…)

vi /var/www/html/index.html

訪問網頁http://localhost,有出現測試的畫面即可

參考這篇取得證書後,要設定在web server上,安裝mod_ssl

yum -y install mod_ssl

編輯ssl.conf

vi /etc/httpd/conf.d/ssl.conf
59行拿掉註解 DocumentRoot “/var/www/html"
60行拿掉註解,並加上網域名稱
75行SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2
100,107,116 指定產生的證書路徑
/etc/letsencrypt/live/cheng.ddns.net/cert.pem
/etc/letsencrypt/live/cheng.ddns.net/privkey.pem
/etc/letsencrypt/live/cheng.ddns.net/chain.pem

將80 port指向443 port

vi /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName cheng.ddns.net
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

重啟服務

 systemctl restart httpd

將防火牆port打開

firewall-cmd --add-service=https --permanent

重新載入防火牆規則

firewall-cmd --reload