【问题标题】:What is my mistake in configure port based virtualhost in Apache server?在 Apache 服务器中配置基于端口的虚拟主机有什么错误?
【发布时间】:2015-10-14 19:50:52
【问题描述】:

我尝试在 APACHE 服务器中配置基于端口的虚拟主机,但出现以下错误

[root@ram conf]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for ram
httpd: Could not reliably determine the server's fully  qualified            domain name, using 127.0.0.1 for ServerName
[Wed Oct 14 15:11:37 2015] [warn] VirtualHost 192.168.2.3:80 overlaps    with VirtualHost 192.168.2.3:80, the first has precedence, perhaps you need a NameVirtualHost directive
 [Wed Oct 14 15:11:37 2015] [warn] NameVirtualHost 192.168.2.3:2233 has no VirtualHosts
 (13)Permission denied: make_sock: could not bind to address [::]:2233
 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:2233
  no listening sockets available, shutting down
  Unable to open logs
                                                       [FAILED]

[root@ram 配置]# 在这种情况下,我的配置文件是

<VirtualHost 192.168.2.3:80>
ServerAdmin root@lopcalhost
DocumentRoot "/opt/sample"
DirectoryIndex "welcome.html"
ServerName "host.admin.com"

  Listen 2233           
  NameVirtualHost 192.168.2.3:2233
  <VirtualHost 192.168.2.3:80>
  ServerAdmin root@lopcalhost   
  DocumentRoot "/opt/web1"
  DirectoryIndex "123.html"
  ServerName "host1.admin.com"

【问题讨论】:

    标签: apache


    【解决方案1】:

    您的问题令人困惑。您确定这不是您的意思或意图吗?

    <VirtualHost 192.168.2.3:2233>
    ServerAdmin root@lopcalhost
    DocumentRoot "/opt/sample"
    DirectoryIndex "welcome.html"
    ServerName "host.admin.com"
    
      Listen 2233           
      NameVirtualHost 192.168.2.3:2233
      <VirtualHost 192.168.2.3:2233>
      ServerAdmin root@lopcalhost   
      DocumentRoot "/opt/web1"
      DirectoryIndex "123.html"
      ServerName "host1.admin.com"
    

    您如何访问这些网站?这是 LAN 上的开发服务器,而不是您的开发机器吗?还是只有局域网才能访问的局域网服务器?

    另外,请尝试注释掉这一行:

    # NameVirtualHost 192.168.2.3:2233
    

    然后重新启动 apache 服务器,看看是否可以纠正它。你想让 apache 只监听 2233 端口还是 2233 端口和 80 端口?

    如果两者都需要,我认为:

    Listen 2233
    Listen 80
    

    添加,基于 cmets: 那么试试这个:

    Listen 2233  
    Listen 80        
    NameVirtualHost *
    
    <VirtualHost 192.168.2.3:80>
    ServerAdmin root@lopcalhost
    DocumentRoot "/opt/sample"
    DirectoryIndex "welcome.html"
    ServerName "host.admin.com"
    ...
    </VirtualHost>
    
    <VirtualHost 192.168.2.3:2233>
    ServerAdmin root@lopcalhost   
    DocumentRoot "/opt/web1"
    DirectoryIndex "123.html"
    ServerName "host1.admin.com"
    ...
    </VirtualHost>
    

    这行得通吗?

    为什么本地机器不使用 127.0.01?唯一需要静态机器 IP 的情况是,如果您从开发服务器外部(即网络中其他位置的机器或网络外部的机器)访问站点,假设路由器中有端口转发等。

    顺便说一句,我意识到您也可能根本不知道您可以使用本地计算机的 etc/hosts 文件根据站点名称发送请求。

    你没有说你使用的是什么操作系统,在 OSX 和 Unix/Linux 中,它是 /etc/hosts(对 osx 不积极,因为我从不使用它,但我认为是一样的)

    https://superuser.com/questions/525688/whats-the-windows-equivalent-of-etc-hosts 示例 windows 路径:如果丢失,只需在此处创建 hosts 文件并保存(我不使用 windows,所以我不知道这是否已更改)。 \WINDOWS\system32\drivers\etc

    使用 /etc/hosts 和 127.0.0.1 的示例:

    127.0.0.1  localhost site1 site2
    

    然后是 apache 配置示例:

    添加,基于进一步的 cmets: 使用 /etc/hosts:

    Listen 80        
    NameVirtualHost *
    
    <VirtualHost 127.0.0.1:80>
    ServerAdmin root@lopcalhost
    DocumentRoot "/opt/sample"
    DirectoryIndex "welcome.html"
    ServerName "site2"
    ...
    </VirtualHost>
    
    <VirtualHost 127.0.0.1:80>
    ServerAdmin root@lopcalhost   
    DocumentRoot "/opt/web1"
    DirectoryIndex "123.html"
    ServerName "site1"
    ...
    </VirtualHost>
    

    这将在您的浏览器中创建两个可以单独访问的站点,例如:http://site1/http://site2/

    【讨论】:

    • 我只想访问本地机器。当我评论“NameVirtualHost 192.168.2.3:2233”时显示错误
    • 我只想在不同的端口上配置两个站点。我想在 :80 中配置 welcome.html ,在 :2233 端口号中配置 123.html 。 @Lizardx
    • 我正在使用 linux redhat 。我也写了和你一样的帖子?我只是没有发布 Listen 80,为什么因为这是在 httpd.conf 文件中定义的默认值。我得到了同样的错误
    • 没关系,我试过了。我的感觉/怀疑是您并没有说关键信息,或者您不清楚您的实际用例是什么,但是在设置良好的系统上很难猜测,没有任何进一步的故障或不寻常的要求,我发布的作品。
    猜你喜欢
    • 1970-01-01
    • 2013-07-21
    • 2021-08-20
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2017-06-14
    • 2012-08-22
    相关资源
    最近更新 更多