我想改变一个工作Apache的example.comconfiguration(exampleIP = 1.2.3.4),从默认的端口80改变到8001端口,使得http://example.com:8001应该工作。 我无法这样做,并将logging我所尝试的。 我想我可能需要iptables的帮助。
我的/ etc / hosts首先是好的
1.2.3.4 example.com
我开始用8001replace80端口在以下地方
/etc/apache2/ports.conf
听1.2.3.4:8001
/etc/apache2/conf.d/virtual.conf
NameVirtualHost 1.2.3.4:8001
/etc/apache2/sites-enabled/example.com
<VirtualHost 1.2.3.4:8001>
ServerName example.com:8001 #UPDATE: ServerName example.com doesn't make a difference either
</虚拟主机>
当我用80replace上述3种情况下的8001时,它就起作用了。 与8001我不能build立连接。 tcpdump也不会显示传入的请求。
由于apache守护进程重新启动时没有抛出任何错误,我试图确认,如果web服务器正在侦听8001
$ sudo lsof -i |grep 8001 apache2 731 root 3u IPv4 46858730 TCP example.com:8001 (LISTEN) apache2 734 www-data 3u IPv4 46858730 TCP example.com:8001 (LISTEN) apache2 736 www-data 3u IPv4 46858730 TCP example.com:8001 (LISTEN) apache2 737 www-data 3u IPv4 46858730 TCP example.com:8001 (LISTEN) apache2 738 www-data 3u IPv4 46858730 TCP example.com:8001 (LISTEN) apache2 739 www-data 3u IPv4 46858730 TCP example.com:8001 (LISTEN)
它似乎在8001听。我甚至试图应用下面的iptable规则到terminal:
$ sudo iptables -A INPUT -p tcp --dport 8001 -j ACCEPT $ sudo iptables -A OUTPUT -p tcp --sport 8001 -j ACCEPT $ sudo iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
我从来没有得到一个被拒绝的日志。 以下是iptables详细模式显示的内容
$ sudo iptables -L -v -n Chain INPUT (policy ACCEPT 3052M packets, 785G bytes) pkts bytes target prot opt in out source destination 25 1690 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8001 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8001 92 6484 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 5/min burst 5 LOG flags 0 level 7 prefix `iptables denied: ' Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 4317M packets, 695G bytes) pkts bytes target prot opt in out source destination 20 1760 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:8001
我不熟悉iptable规则,所以我错过的任何规则的提示将是伟大的。 阅读其他线程我也想知道这是否是一个原因。
$ cat /proc/sys/net/ipv4/conf/eth0/forwarding 0
有了这些信息,有什么可以阻止8001上运行的web服务器而不是80上的提示?
更新1:我试图冲洗所有的iptable规则
$ sudo iptables -X $ sudo iptables -F
我也试图看看tcpdump是否捕捉任何东西
sudo tcpdump -i eth0 port 8001 -v
它不在8001上,而是将端口更改为80(再次在^ 3的位置),并且确实如此。
我试图寻找既定和倾听过程
$ netstat -an tcp 0 1.2.3.4:8001 0.0.0.0:* LISTEN
最后从我的本地机器,我也试过curl
curl http://1.2.3.4:8001 -v * About to connect() to 1.2.3.4 port 8001 (#0) * Trying 1.2.3.4... No route to host * couldn't connect to host * Closing connection #0 curl: (7) couldn't connect to host
更新2
另外,捕获iptables错误的我的/ etc / log / messages似乎会抛出以下错误。 但事实certificate,当你进入和退出tcpdump的时候会出现这些。
Jan 22 09:30:31 node1 kernel: device eth0 entered promiscuous mode Jan 22 09:30:31 node1 kernel: audit(1264152631.798:54): dev=eth0 prom=256 old_prom=0 auid=4294967295 Jan 22 09:30:33 node1 kernel: device eth0 left promiscuous mode
更新3发现这在tcpdump常见问题
…这可能是因为你正在捕获的接口被插入交换机; 在交换networking上, 两个端口之间的单播stream量不一定会出现在其他端口上,只有广播和多播stream量将被发送到所有端口。
…这将表明,如果你嗅探一个10Mb的端口, 你不会看到stream量发送到100Mb端口,反之亦然…
…如果您的机器没有插入交换networking或双速集线器,或者插入了交换networking,但端口已设置为复制所有stream量,则问题可能在于networking接口你正在捕获不支持“混杂”模式 ,或者因为你的操作系统不能把界面变成混杂模式…
所以总结一下这个奇特的例子:
在你提到的第3步
/etc/apache2/sites-enabled/example.com
<VirtualHost 1.2.3.4:80> ServerName example.com:8001 … </VirtualHost>
这是不正确的。 它应该是
<VirtualHost 1.2.3.4:8001> ServerName example.com … </VirtualHost>
如果它不打扰你,尝试绑定到任何接口:
Listen 0.0.0.0:8001
和ServerName应该是:
ServerName example.com
剩下的就像你已经configuration好的一样。 请注意,NameVirtualHost和VirtualHost必须具有相同的签名。 而且因为它是一个基于名字的虚拟主机,所以你需要在浏览器中添加一行:
1.2.3.4 example.com
并在浏览器中使用http://example.com:8001/作为URL(curl,wget,MSIE,Firefox)
用于debugging使用:
tshark -V -i eth0 port 8001 or port 80
看看在error.log和access.log中发生了什么
监听不执行虚拟主机。 http://httpd.apache.org/docs/2.0/bind.html#virtualhost
添加到/etc/apache2/ports.conf只听8001
确保include包含在apache2.conf文件中的虚拟主机之前。 在包含行之前,您还可以将Listen命令直接放到apache2.conf文件中。
干杯
毕竟当我联系到托pipe人员时,这是一个防火墙问题。
将试图让他们详细说明他们实际上做了什么来执行这个。
最后是一个很好的系统pipe理员的练习。 感谢大家…