CentOS部署Apache并外網(wǎng)訪問完整指南
環(huán)境準(zhǔn)備與Apache安裝
通過SSH連接至CentOS服務(wù)器,執(zhí)行以下命令更新系統(tǒng)并安裝Apache:
sudo yum update -y
sudo yum install httpd -y
安裝完成后啟動(dòng)服務(wù)并設(shè)置開機(jī)自啟:
sudo systemctl start httpd
sudo systemctl enable httpd
防火墻配置與端口開放
配置防火墻允許HTTP/HTTPS流量:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
外網(wǎng)訪問配置要點(diǎn)
- 檢查服務(wù)器公網(wǎng)IP地址:
curl ifconfig.me
- 驗(yàn)證SELinux狀態(tài):
sestatus
- 臨時(shí)關(guān)閉SELinux(測試用):
setenforce 0
網(wǎng)絡(luò)調(diào)試與驗(yàn)證
本地訪問測試:
curl 127.0.0.1
外網(wǎng)訪問測試:
- 瀏覽器訪問
http://服務(wù)器公網(wǎng)IP
- 檢查云服務(wù)器安全組規(guī)則
- 驗(yàn)證路由器端口轉(zhuǎn)發(fā)設(shè)置
常見問題解決方案
# 查看防火墻狀態(tài)
sudo systemctl status firewalld
# 檢查80端口監(jiān)聽
sudo netstat -tulnp | grep 80
# 查看Apache錯(cuò)誤日志
sudo tail -f /var/log/httpd/error_log
安全增強(qiáng)建議
- 保持SELinux處于enforcing模式
- 配置HTTPS加密連接
- 定期更新系統(tǒng)安全補(bǔ)丁