Ubuntu 域名共享的可行方案与实现
概念澄清
多域名共享同一台 Ubuntu 服务器
使用 Nginx 多域名虚拟主机(基于域名)
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / { try_files $uri $uri/ =404; }
}
使用 Apache 基于域名的虚拟主机
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
将 Ubuntu 作为 DNS 服务器供内网共享解析
options {
directory "/var/cache/bind";
forwarders { 8.8.8.8; 8.8.4.4; };
dnssec-validation auto;
};
zone "example.com" {
type master;
file "/etc/bind/db.example.com";
};
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2024102201 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
@ IN NS ns1.example.com.
@ IN A 192.168.1.10
www IN A 192.168.1.10
ns1 IN A 192.168.1.10
常见问题与快速排查