安裝httpd
yum -y install httpd
刪除歡迎頁面
rm -f /etc/httpd/conf.d/welcome.conf
編輯httpd.conf
vi /etc/httpd/conf/httpd.conf

95行 ServerName cheng.ddns.net:80



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

60行拿掉註解,並加上網域名稱


/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