我开始使用我的服务器上的PHP本地服务器
php -S 0.0.0.0 8283 -t testServer/
使用curl localhost:8283我能够得到index.php文件的结果
但是当我使用我的服务器IP访问它,我无法访问该端口。
任何时候我做netstat -tuplen 。 我也可以看到那个港口
如何通过http请求使端口8283可用?
我用过这个
# /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8283 -j ACCEPT # service iptables save # service iptables restart
仍然没有工作
这是从我的服务器上的telnet输出
telnet XX.XX.X.XXX 8283 Trying XX.XX.X.XXX... Connected to XX.XX.X.XXX. Escape character is '^]'. GET / HTTP/0.9 200 OK Connection: close X-Powered-By: PHP/5.5.19 Content-type: text/html Hello World !Connection closed by foreign host.
这个是来自我的电脑
telnet XX.XX.X.XXX 8283 Trying XX.XX.X.XXX... telnet: Unable to connect to remote host: No route to host
NMAP结果
sudo nmap -p 8283 XX.XX.X.XXX Starting Nmap 5.21 ( http://nmap.org ) at 2015-02-04 19:18 IST Nmap scan report for srv1.domain.com (XX.XX.X.XXX) Host is up (0.035s latency). PORT STATE SERVICE 8283/tcp filtered unknown Nmap done: 1 IP address (1 host up) scanned in 0.37 seconds
IPTABLES输出
/sbin/iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8282 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8283 state NEW,ESTABLISHED Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
-S选项的localhost参数告诉PHP只能监听localhost或127.0.0.1。 如果你想让它在外部可用,你需要使用外部IP地址/主机名或“0.0.0.0”,虽然快速阅读手册页并没有明确指出0.0.0.0会起作用。
如果您只想testing是否可以使用该端口,请使用Netcat:
在你的服务器上
nc -l 0.0.0.0 8283
注意 : -l开关指示netcat 侦听端口8080。
在你的客户端
telnet 1.2.3.4 8283
要么
nc 1.2.3.4 8283