我有一大堆IP地址的服务器,我只希望Apache在其中一个服务器上进行监听。 这听起来并不是一件很难的事情,而我之前曾经做过一次,但这次我遇到了一些麻烦。 首先,我现在在这里,根据我的理解:
Apache正在监听80端口的每个地方,它只能监听正确的IP。
/etc/apache2$ grep -R ":80" . ./sites-available/default:<VirtualHost 192.168.0.82:80> ./httpd.conf:<VirtualHost 192.168.0.82:80> ./ports.conf:NameVirtualHost 192.168.0.82:80 ./sites-enabled/000-default:<VirtualHost 192.168.0.82:80>
没有提及在0.0.0.0上收听。
/etc/apache2$ grep -R "0\.0\.0\.0" .
然而… Apache拒绝启动。
/etc/apache2$ sudo /etc/init.d/apache2 start * Starting web server apache2 (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. [fail]
如果有人问,我不受这个地址的约束:
/etc/apache2$ sudo netstat -nap | grep :80 tcp 0 0 192.168.0.83:80 0.0.0.0:* LISTEN 2822/node
/var/log/apache2/error.log的错误日志只是说:
[Wed Aug 08 03:30:18 2012] [notice] caught SIGTERM, shutting down
我错过了Apache的configuration吗? 有什么我不记得去寻找? 为什么这不像我想起的那样简单?
即使您指定了某些IP来运行NameVirtualHost,Apache也会默认绑定到所有内容。
把这个添加到你的ports.conf中:
Listen 192.168.0.82:80
参考: http : //httpd.apache.org/docs/2.2/bind.html
查看/etc/apache2/ports.conf文件。
你会发现一个指令,如:
Listen 80
CentOS框的评论描述了这个选项:
# # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, in addition to the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses (0.0.0.0) # #Listen 12.34.56.78:80
对于你想要的,将Listen 80行改为Listen 192.168.0.82:80 。
您现在无法启动Apache,因为它试图在所有接口(0.0.0.0名称)上绑定到端口80,并且您在192.168.0.83:80上监听node 。
虚拟主机块中的IP意味着特定的虚拟主机将对进入该IP地址的请求做出响应。 它没有指定Apache如何绑定到它所看到的接口。
听指令是你在找什么:
Listen 192.168.0.82:80
更多信息在文档中 。
根据Apache文档使用以下内容:
听192.168.0.82:80
在某些情况下(不是全部),可以进一步做一些工作:
听some_name_in_my_localhost:80
这样,当你有一个Apache服务器场时,你可以使你的apacheconfiguration可移植。 这有利有弊(就像所有其他事情一样)。