CentOS6配置httpd網(wǎng)站:Apache服務(wù)器搭建詳解
環(huán)境準(zhǔn)備與httpd安裝
通過SSH連接至CentOS6服務(wù)器,執(zhí)行以下命令更新系統(tǒng)并安裝Apache:
yum update -y
yum install httpd -y
基礎(chǔ)服務(wù)配置與管理
修改主配置文件/etc/httpd/conf/httpd.conf
,設(shè)置ServerName參數(shù):
ServerName localhost:80
啟動(dòng)服務(wù)并設(shè)置開機(jī)自啟:
service httpd start
chkconfig httpd on
虛擬主機(jī)配置實(shí)踐
在/etc/httpd/conf.d/
目錄創(chuàng)建vhost.conf
文件,配置域名指向:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html
ServerName www.example.com
ErrorLog logs/example-error_log
CustomLog logs/example-access_log common
</VirtualHost>
目錄權(quán)限與防火墻設(shè)置
調(diào)整網(wǎng)站根目錄權(quán)限:
chmod -R 755 /var/www/html
chown -R apache:apache /var/www/html
開放80端口訪問權(quán)限:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart
服務(wù)驗(yàn)證與故障排查
執(zhí)行配置語法檢查:
apachectl configtest
重啟服務(wù)使配置生效:
service httpd restart
通過瀏覽器訪問服務(wù)器IP或綁定域名,查看/var/log/httpd/
目錄日志文件排查異常情況。