我试图将网站使用的端口从80改为8080。
这是我的/etc/apache2/ports.conf :
NameVirtualHost *:80 NameVirtualHost *:8080 Listen 80 Listen 8080
这是我的VirtualHost文件:
<VirtualHost *:8080> # Admin email, Server Name (domain name), and any aliases ServerAdmin [email protected] ServerName www.foo.com ServerAlias foo.com # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /var/www/foo.com/ </VirtualHost>
netstat -lntp输出:
tcp6 0 0 :::8080 :::* LISTEN 7267/apache2 tcp6 0 0 :::80 :::* LISTEN 7267/apache2
当我在我的VirtualHost中使用端口8080重新启动Apache时,网站出现故障(无法连接到网站中的铬错误),如果我更改回80端口,所有工作正常。
我在这里做错了什么?
更新:
主机是Debian 7的linode机器。
我也没有启用SElinux。
/etc/hostsconfiguration:
127.0.0.1 <foo.com> <serverhostname> 127.0.1.1 debian # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
我认为端口8080是正确打开的,这里是iptables -L -n -v的输出:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 467 36136 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 REJECT all -- * * 0.0.0.0/0 127.0.0.0/8 reject-with icmp-port-unreachable 103K 11M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 600 35296 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 30 1532 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 42 2308 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 6860 411K ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 44 2848 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 860 57824 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: " 968 67687 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination
curl -v http://localhost:8080输出:
* About to connect() to localhost port 8080 (#0) * Trying ::1... * connected * Connected to localhost (::1) port 8080 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.26.0 > Host: localhost:8080 > Accept: */* > * additional stuff not fine transfer.c:1037: 0 0 * HTTP 1.1 or later with persistent connection, pipelining supported < HTTP/1.1 301 Moved Permanently < Date: Mon, 10 Jun 2013 09:58:08 GMT < Server: Apache/2.2.22 (Debian) < X-Powered-By: PHP/5.4.4-14 < X-Pingback: http://www.foo.com/xmlrpc.php < Location: http://localhost/ < Vary: Accept-Encoding < Content-Length: 0 < Content-Type: text/html; charset=UTF-8 < * Connection #0 to host localhost left intact * Closing connection #0
也许端口8080被iptables阻塞。 使用iptables -L -n -v查看是否启用了iptables,并有效地将数据包阻塞到端口8080。
你正在运行什么发行版? 您可能已启用SElinux,这是拒绝您的请求。
检查SElinux是否已经启动
# sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted
如果当前模式强制执行尝试在故障排除期间禁用它:
#setenforce 0
如果它现在正在工作,则必须通过audit2allow创build自定义SElinux策略。
从你的netstat输出看起来,端口8080正在监听ipv6。 你使用ipv6连接?
httpd是在ipv4上监听的吗?
你可以运行netstat -lntp|grep 80 ,向我们展示所有的输出,而不是粘贴在你认为相关的位上。
我build议以下解决方法,
检查Apacheconfiguration
apachectl configtest
从服务器本身testing页面并检查HTTP输出
wget -O – “localhost”
检查Apache的error_log到什么样的错误,你的网站上可能是一个configuration不允许端口8080
尝试只使用端口8080看看会发生什么
NameVirtualHost *:8080 Listen 8080
只创build一个在端口8080上侦听的VirtualHost
好的,我看到这个端口是开放的。 发生了什么事
curl -v http://localhost:8080
?
我相当肯定你的问题是,Apache正在监听的IPv6至less为1。
你可以让我知道,如果你想使用ipv4,ipv6或两者?
请运行以下内容并粘贴到输出中:
ifconfig -a
这应该显示所有在接口上运行的IP地址。
假设您使用http://<servername>.<foo.com>作为chrome中的URL,那么请同时运行这些命令,并粘贴命令并输出:
dig <servername>.<foo.com> dig <servername> dig -t A <servername>.<foo.com> dig -t A <servername> dig -t AAAA <servername>.<foo.com> dig -t AAAA <servername>
我假设你想使用ipv4而不是ipv6。 如果是这样的话,试试这个:
改变你的/ etc / hosts看起来像这样:
127.0.0.1 localhost 10.0.0.1 <servername>.<foo.com> <servername> # The following lines are desirable for IPv6 capable hosts ff02::1 ip6-allnodes ff02::2 ip6-allrouters
但是用你的ipv4地址replace10.0.0.1。 然后重新启动Apache。 再用浏览器和curl再试一次。
用curl试试localhost和<servername>.<foo.com> 。
根据你的curltesting本地主机apache是听8080和响应,虽然redirect你301与http:// localhost /但似乎来自默认网站。
根据你的Apacheconfiguration你正在configuration一个命名的虚拟主机,与ServerName http://www.foo.com
尝试:
$ telnet localhost 8080 GET / HTTP/1.0 Host: www.foo.com
结束两行返回。 如果这是返回内容,这意味着服务器configuration工作正常。 所以你的问题在你和你的服务器之间。