【问题标题】:Creating subdomains on apache2 server with dynamic IP使用动态 IP 在 apache2 服务器上创建子域
【发布时间】:2013-12-06 15:43:25
【问题描述】:

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

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

我修改了apache vhosts examples page 上的代码并将其放入我的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 文件中有一个匹配的配置条目。删除它后,一切正常。

【问题讨论】:

    标签: apache ubuntu subdomain httpd.conf dynamic-ip


    【解决方案1】:

    如果您将 localhost 替换为 *,您的 apache conf 似乎是正确的。这意味着你应该使用NameVirtualHost *:80&lt;VirtualHost *:80&gt;

    但是,您必须告诉 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 不是错误,它只是一个警告,所以您不必担心

    【讨论】:

    • 我尝试使用 *:80 但仍然出现错误,这就是我切换到 localhost 的原因。
    • Apache.... tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 16644/apache2
    • 那么 apache 可以工作吗?尝试使用sudo apache2ctl restart 而不是sudo /etc/init.d/apache2 restart
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 2015-05-03
      • 2013-08-23
      • 1970-01-01
      • 2015-06-04
      相关资源
      最近更新 更多