CentOS LAMP 域名解析排查与修复
一、先快速定位问题类型
nslookup www.example.com、dig www.example.com。systemctl status NetworkManager 或 systemctl status network;必要时 systemctl restart NetworkManager / systemctl restart network。echo -e "nameserver 223.5.5.5\nnameserver 8.8.8.8" > /etc/resolv.conf,再测试解析是否恢复。二、修复服务器 DNS 配置
echo -e "nameserver 223.5.5.5\nnameserver 8.8.8.8" > /etc/resolv.confDNS1=223.5.5.5、DNS2=8.8.8.8、PEERDNS=yessystemctl restart network(或 systemctl restart NetworkManager)。ping www.example.com、nslookup www.example.com 应返回正确 IP。三、LAMP 层面的域名访问与虚拟主机配置
IncludeOptional conf.d/*.conf。<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/example
<Directory /var/www/html/example>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/example-error.log
CustomLog /var/log/httpd/example-access.log combined
</VirtualHost>
mkdir -p /var/www/html/example && echo "<?php phpinfo(); ?>" > /var/www/html/example/index.phphttpd -t && systemctl restart httpd服务器IP www.example.com。四、防火墙与 SELinux 放行
firewall-cmd --permanent --add-port=80/tcp && firewall-cmd --reloadsetenforce 0;如需永久调整,编辑 /etc/selinux/config。journalctl -xe | grep -i dns,或 journalctl -u httpd。五、常见现象与对应处理
systemctl restart nscd。