问题原文
原帖链接 · Anshad Vattapoyil · CC BY-SA 3.0
I have a domain betasquirrel.com purchased from GoDaddy and a VPS with Ubuntu 16.04. And I hosted the domain successfully using BIND9 as below:
Created virtual-host for betasquirrel.com in Apache and placed the files. Next created two hosts ns1.betasquirrel.com and ns2.betasquirrel.com in GoDaddy by pointing to VPS IP address.
Next configured BIND9,
/etc/bind/zones/master/db.betasquirrel.com
;
; BIND data file for betasquirrel.com
;
$TTL 3h
@ IN SOA ns1.betasquirrel.com. admin.betasquirrel.com. (
1 ; Serial
3h ; Refresh after 3 hours
1h ; Retry after 1 hour
1w ; Expire after 1 week
1h ) ; Negative caching TTL of 1 day
;
@ IN NS ns1.betasquirrel.com.
@ IN NS ns2.betasquirrel.com.
betasquirrel.com. IN MX 10 mail.betasquirrel.com.
betasquirrel.com. IN A 144.217.163.139
ns1 IN A 144.217.163.139
ns2 IN A 144.217.163.139
www IN CNAME betasquirrel.com.
mail IN A 144.217.163.139
ftp IN CNAME betasquirrel.com.
/etc/bind/zones/master/db.144.217.163
;
; BIND reverse data file for 163.217.144.in-addr.arpa
;
$TTL 604800
163.217.144.in-addr.arpa. IN SOA ns1.betasquirrel.com. admin.betasquirrel.com. (
1 ; Serial
3h ; Refresh after 3 hours
1h ; Retry after 1 hour
1w ; Expire after 1 week
1h ) ; Negative caching TTL of 1 day
;
163.217.144.in-addr.arpa. IN NS ns1.betasquirrel.com.
163.217.144.in-addr.arpa. IN NS ns2.betasquirrel.com.
139.163.217.144.in-addr.arpa. IN PTR betasquirrel.com.
/etc/bind/named.conf.local
zone "betasquirrel.com" {
type master;
file "/etc/bind/zones/master/db.betasquirrel.com";
};
zone "163.217.144.in-addr.arpa" {
type master;
file "/etc/bind/zones/master/db.144.217.163";
};
In named.conf.options
forwarders {
213.186.33.99;
};
/etc/init.d/bind9 restart
Next added the name-servers ns1.betasquirrel.com and ns2.betasquirrel.com in GoDaddy and the site started working.
Now how can I host sub-domains like demo.betasquirrel.com. I have just created virtual-hosts and it's not working.
/etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
search demo.betasquirrel.com
search betasquirrel.com
nameserver 213.186.33.99
search local
/etc/apache2/sites-available/betasquirrel.com.conf
<VirtualHost *:80>
ServerName betasquirrel.com
ServerAlias www.betasquirrel.com
DocumentRoot /var/www/html/betasquirrel.com/htdocs
DirectoryIndex index.php index.html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/sites-available/demo.betasquirrel.com.conf
<VirtualHost *:80>
ServerName demo.betasquirrel.com
ServerAlias www.demo.betasquirrel.com
DocumentRoot /var/www/html/demo.betasquirrel.com/htdocs
DirectoryIndex index.php index.html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
已采纳解答
原帖链接 · cnst · CC BY-SA 3.0
As per your comment, you've removed the demo entries, and the rest of your domain started working again, which leads us to the actual entries that were removed, which were all wrong taken together:
-demo.betasquirrel.com. IN A 144.217.163.139
-demo IN A 144.217.163.139
-demo IN CNAME demo.betasquirrel.com.
First of all, the first two entries are identical -- after expansion, both the left and the right sides are identical between the two, which might result in an error, because the same identical entry is effectively present twice.
However, the most problematic issue comes from the presence of both the
AandCNAMErecords at the same time -- theCNAMErecord means that this name refers to a different host instead; and as such, the name cannot simultaneously contain ANY other records, as it's merely an alias.To put it in filesystem terms, an
Arecord is like a line in a file, and can coexist with pretty much any other record (lines in the same file). However, aCNAMEis like a symboliclink-- if a given file is a symbolic link, it cannot itself also contain any other random lines, too.Moreover, looking more closely into your CNAME, it's actually a link from itself to itself (after the expansion), which is also entirely wrong in itself.
Solution:
Either add a CNAME record, or an A record; the difference is in semantics, and there's no "right" or "wrong" solution here. You cannot add both at the same time, however. Moreover, if adding a CNAME record, it must point to an existing record that contains the required A record, and it definitely cannot simply point back to itself.
Option 0:
+demo IN A 144.217.163.139
Option 1a:
+demo IN CNAME @
Option 1b:
+demo IN CNAME betasquirrel.com.
Option 2a:
+demo IN CNAME www
Option 2b:
+demo IN CNAME www.betasquirrel.com.
You cannot take all the options simultaneously at the same time!!!
No, like seriously, you can't! It just won't work at all. Don't blame us for it.
Note that options a and b are identical -- the only difference is in the syntax that you use in your config file, but when it's loaded by the server into the structures representing the DNS protocol, there should not be any difference between either notation.
P.S. Also note that the + sign in front of the examples signifies the line that you must add, it shouldn't be the actual part of the file.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
