0

所以基本上我在我的服务器上创建子域时遇到问题。我在 Ubuntu 12.04 服务器上运行 apache2,并使用 No-IP.com 设置了动态 IP。

我有 mydomain.com 工作,但想创建 test.mydomain.com 指向我的 /var/www/ 目录(我的网站的所有内容都位于该目录)中的子文件夹。

我修改了apache vhosts 示例页面上的代码并将其放入我的 httpd.conf 文件中:

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost localhost:80

<VirtualHost localhost:80>
DocumentRoot /var/www/
ServerName mydomain.com

# Other directives here

</VirtualHost>

<VirtualHost localhost:80>
DocumentRoot /var/www/test
ServerName test.mydomain.com

# Other directives here

</VirtualHost>

当我尝试重新启动服务时:

sudo /etc/init.d/apache2 restart

 * Restarting web server apache2                                                                                                                                                                            apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

任何帮助是极大的赞赏。如果我忘记包含任何必要的信息,请告诉我。

更新 我尝试使用 *:80 但仍然出现错误,这就是我切换到 localhost 的原因。

sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                                                                                                                                            apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Nov 21 15:03:51 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Nov 21 15:03:51 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

更新我弄清楚发生了什么。我的 ports.conf 文件中有一个匹配的配置条目。一旦我删除它,一切正常。

4

2 回答 2

0

如果您将 localhost 替换为 *. 这意味着您应该使用NameVirtualHost *:80<VirtualHost *:80>

但是,您必须告诉 DNS 服务器将子域转发到您的动态 IP。由于您拥有来自付费 DNS 服务的 .com 域,因此您必须登录您的 DNS 提供商并将 A 记录或 CNAME 记录设置到您的 IP(添加您在主 .com 域中的相同设置)。如果您使用 ddclient 或类似客户端自动更新域,您可以将其配置为也更新子域。

无论如何,使用命令nslookup yourdomain.comnslookup subdomain.domain.com查看子域是否更新成功。请注意,DNS 中的更新可能需要数小时才能真正生效。

编辑:

抱歉刚刚注意到:(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80。这意味着其他人已经在使用端口 80,因此 apache 服务器无法绑定到该地址。用于sudo netstat -anltp | grep :80查看哪个程序绑定了端口 80。此外,请检查您的 conf 文件以确保您没有更多NameVirtualHost *:80指令。

最后,apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName不是错误,它只是一个警告,所以你不应该担心这个

于 2013-11-21T22:53:43.590 回答
0

可能有服务使用端口:80 netstat -tulpn |grep :80在命令行上尝试查看哪个服务正在占用此端口。就我而言,它是 nginx。我停止了服务,然后启动了我想使用的服务(apache2)。

于 2016-04-01T11:08:39.287 回答