我正在尝试将网站使用的端口从 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
8080
当我使用VirtualHost 中的端口重新启动 apache 时,网站就会关闭(chrome 中无法连接到网站错误),如果我改回端口80
,一切都会再次正常工作。
我在这里做错了什么?
更新:
主机是一台装有 Debian 7 的 linode 机器。
另外我还没有启用 SElinux。
配置/etc/hosts
:
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
答案1
可能是 iptables 阻止了端口 8080。使用iptables -L -n -v
来查看 iptables 是否已启用并有效阻止发往端口 8080 的数据包。
答案2
你运行的是什么发行版?你可能启用了 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
如果它现在可以工作,您必须通过创建自定义 SElinux 策略audit2allow
。
答案3
从您的 netstat 输出来看,端口 8080 似乎正在监听 ipv6。您是否使用 ipv6 进行连接?
httpd 是否正在监听 ipv4?
您能否运行netstat -lntp|grep 80
并向我们展示所有的输出,而不是仅仅粘贴您认为相关的部分。
答案4
好的,我看到端口已打开。发生了什么事
curl -v http://localhost:8080
?