事前 準備
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Step 1 Apache 安裝 與 初步設定
dnf install httpd # 安裝 Apache (網路連線) 指令安裝 Apache 。
# 也安裝其他必需的軟件包 等待 安裝完成 看看 多了哪些東西 ?
Step 2 管理 Apache 服務
systemctl enable httpd # 電腦重啟時,會自動開啟 httpd
systemctl stop httpd # 關閉 Apachche
systemctl restart httpd # 重啟 Apache
systemctl status hte
systemctl start httpd # 開啟 Apatpd # Apache 當下狀況
systemctl reload httpd # 重新載入 相關參數
Step 3 firewall-cmd看看 防火牆
firewall-cmd --permanent --zone=public --add-service=http # 打開 port(80)
firewall-cmd --permanent --zone=public --add-service=https # 打開 port(443)
firewall-cmd --reload # 防火牆規則,重新載入.
firewall-cmd --list-services # 查看 防火牆 是否開啟 http, httpd.
Step 4 測試 Apache 設置
httpd -v # 使用以下命令查看已安裝的 Apache 版本詳細信息。
現在使用 Firefox 瀏覽器 訪問 服務器的 IP 地址或指向服務器 IP 的域名。
http://127.0.0.1 http://localhost http://mail.dxqerp.com
應該 出現 Apache 的預設畫面 (HTTP Server Test Page)
Step 5 測試 自己的 測試畫面
echo " Hi 天南訊息科技 " > /var/www/html/index.html
http://127.0.0.1 http://localhost http://mail.dxqerp.com
Step 6 虛擬主機 (first.com ) 建立 port 80
# 建立 mail.dxqerp.com (主要 虛擬主機)
<VirtualHost 192.168.17.9:80>
ServerAdmin admin@first.com
DocumentRoot /var/www/html
ServerName mail.dxqerp.com
ServerAlias mail.dxqerp.com
<Directory /var/www/html>
#Allowoverride all uncomment if required
</Directory>
ErrorLog logs/dxqerp.com_error.log
CustomLog logs/dxqerp.com_access.log combined
</VirtualHost>
# 建立 first.com 虛擬主機 (第二個虛擬主機)
mkdir -p /var/www/first.com
echo " Hi www.first.com 虛擬主機 " > /var/www/first.com/index.html # 虛擬機 的 index.html
vim /etc/httpd/conf.d/first.com.conf # 建立虛擬主機 環境設定 檔
<VirtualHost 192.168.17.8:80>
ServerAdmin admin@first.com
DocumentRoot /var/www/first.com
ServerName www.first.com
ServerAlias www.first.com
<Directory /var/www/first.com>
#Allowoverride all, Uncomment if required
</Directory>
ErrorLog logs/first.com_error.log
CustomLog logs/first.com_access.log combined
</VirtualHost>
# 建立 Second.com 虛擬主機 (第三個虛擬主機)
<VirtualHost 192.168.17.9:80 >
DocumentRoot /var/www/second.com
ServerName www.second.com
ServerAlias www.second.com
<Directory /var/www/second.com>
Allowoverride all ###Uncomment if required
</Directory>
ErrorLog logs/second.com_error.log
CustomLog logs/second.com_access.log combined
</VirtualHost>
Step 7 安全的 Apache 服務器
安全是託管最重要的部分。 編輯Apache主配置文件
vim /etc/httpd/conf/httpd.conf # 在文件末尾添加以下值. ServerTokens Prod # 不顯示 Apache 版本號. ServerSignature Off # 當查詢的網頁不存在, 不顯示 相關的訊息. TraceEnable Off # 避免 Trace 方法 的攻擊.
THE END
參考
https://tecadmin.net/install-apache-centos8.
https://wizardforcel.gitbooks.io/vbird-linux-server-3e/content/149.html