Linux 域名设置全指南
一、常见场景与总体思路
二、公网网站绑定域名的步骤
server {
listen 80;
server_name your_domain.com www.your_domain.com;
root /var/www/your_domain;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
启用站点并测试配置:sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
<VirtualHost *:80>
ServerName your_domain.com
DocumentRoot /var/www/your_domain
<Directory /var/www/your_domain>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
启用站点并重启服务:sudo a2ensite your_domain.conf
sudo apache2ctl configtest && sudo systemctl reload apache2
三、本机与内网测试的设置
sudo hostnamectl set-hostname example.com,便于系统标识与日志显示。四、系统与网络层的域名相关配置
nameserver 8.8.8.8
nameserver 8.8.4.4
注意:在部分发行版上该文件由 systemd-resolved、NetworkManager 或 resolvconf 管理,手动修改可能被覆盖,应通过对应工具或网络配置文件进行持久化设置。五、常见问题与快速排查
systemctl reload nginx),确认语法无误(如 nginx -t)。/var/log/nginx/error.log;Apache:/var/log/apache2/error.log)。