我想使用DNS别名来configuration我的一个域指向服务器上的特定目录。
这是我所做的:
1)在域设置中更改IP地址,它工作
$ ping www.example.com PING example.com (124.205.62.xxx): 56 data bytes 64 bytes from 124.205.62.xxx: icmp_seq=0 ttl=48 time=53.088 ms 64 bytes from 124.205.62.xxx: icmp_seq=1 ttl=48 time=52.125 ms ^C --- example.com ping statistics --- 2 packets transmitted, 2 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 52.125/52.606/53.088/0.482 ms
2)添加可用站点和启用站点
$ ls -l /etc/apache2/sites-available/ total 16 -rw-r--r-- 1 root root 948 2010-04-14 03:27 default -rw-r--r-- 1 root root 7467 2010-04-14 03:27 default-ssl -rw-r--r-- 1 root root 365 2010-06-09 18:27 example.com $ ls -l /etc/apache2/sites-enabled/ total 0 lrwxrwxrwx 1 root root 26 2010-06-09 15:46 000-default -> ../sites-available/default lrwxrwxrwx 1 root root 33 2010-06-09 18:17 001-example.com -> ../sites-available/example.com
但它不起作用,当我打开www.example.com的浏览器,它显示111错误:
The following error was encountered: Connection to 124.205.62.48 Failed The system returned: (111) Connection refused
以下是example.com的configuration:
$ cat /etc/apache2/sites-enabled/001-example.com <virtualhost *:80> DocumentRoot "/vhosts/example.com/htdocs/" ServerName www.example.com ServerAlias example.com <Location /> Order Deny,Allow Deny from None Allow from all </Location> #Include /etc/phpmyadmin/apache.conf ErrorLog /vhosts/example.com/logs/error.log CustomLog /vhosts/example.com/logs/access.log combined
你能告诉我如何解决这个问题吗?
这是正确的基于名称的虚拟主机configuration 。
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.domain.tld ServerAlias domain.tld *.domain.tld DocumentRoot /www/domain </VirtualHost> <VirtualHost *:80> ServerName www.otherdomain.tld DocumentRoot /www/otherdomain </VirtualHost>
尝试将此行添加到客户机中的hosts文件(/ etc / hosts或C:\ WINDOWS \ System32 \ drivers \ etc \ hosts)中:
124.205.62.48 www,example.com
如果在重新启动浏览器后,www.example.com网站工作的问题是与DNS有关,否则问题是与Apache有关(检查系统和Apache日志)。
我绝对认为,Apacheconfiguration可能是问题,而不是DNS。 你的虚拟主机部分说*:80。 我希望你明白这一点。 我想你已经有一个站点在默认端口(80)上运行在该服务器上。 你正在尝试添加另一个站点到端口80.正如你可能知道你不能有两个进程绑定到相同的端口和相同的IP。 如果这是问题,那么要么绑定到一个非标准的端口,并让用户在浏览器中键入端口,并连接或使用不同的IP来绑定,而不是你提到的所有(* ==全部)。 我还没有做名字为基础的虚拟主机,基于名称的虚拟主机应该也是另一种select。 无论如何,你的Apache错误日志应该清楚地表明问题是什么。 错误日志和访问日志的位置应在主httpd.conf中提及。 这通常出现在/etc/httpd/conf/httpd.conf和这些虚拟主机conf的链接里面。 在虚拟主机部分定义的错误日志和访问日志也将大大有助于减轻发现问题的麻烦。
你必须做两个想法:
1)设置hosts文件。 在Linux中,在%WINDOWS%\ System32 \ drivers \ etc \ hosts中的Windows中有/ etc / hosts:
124.205.62.48 www.example.com www.othersite.com
2)以这种方式设置Apache NamedVirtualHost:
NameVirtualHost 124.205.62.48:80 <VirtualHost www.example.com:80> ServerName www.example.com ServerAlias example.com *.example.com DocumentRoot /www/example </VirtualHost> <VirtualHost www.othersite.com:80> ServerName www.othersite.com ServerAlias othersite.com *.othersite.com DocumentRoot /www/othersite </VirtualHost>
编辑1:注意1:你可以检查,如果Apache正在使用这个命令监听所有的接口:
netstat -tpln
如果会有这样一行:
tcp tcp 0 0.0.0.0:80 0.0.0.0:* LISTEN
然后,Apache正在监听每个接口,并且每个方面都可以。 如果有这样的线路:
tcp tcp 0 127.0.0.1:80 0.0.0.0:* LISTEN
然后,Apache只在“lo”接口上进行侦听,并且Apache的configuration文件中存在问题。
Notice2:
如果Notice1正常,则必须通过以下方式检查防火墙:
iptables -L -n
我知道,一些RedHat克隆有非常严格的防火墙,拒绝访问除ssh之外的所有端口…您可以尝试停止防火墙,并尝试,如果您可以连接到Apache,然后控制/添加防火墙规则…