我在服务器上使用 php 启动了本地服务器。(尝试在端口 8080/8283 上工作。他们中的任何一个都会做。
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 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
试试
php -S 0.0.0.0 8080 -t testServer/
通过使用localhost
您将仅绑定127.0.0.1
地址:该地址无法通过其他地址而不是localhost
或localhost.localdomin
访问。
现在,通过使用0.0.0.0
您将绑定所有接口。或者,您可以在要公开服务的位置使用主机地址。
您不必使用本地主机,您必须使用外部IP地址:
php -S <ip-address> 8080 -t testServer/
本地主机映射在 IP 127.0.0.1
上,因此只能从 YOR 服务器使用。
您显式绑定到localhost
。如果要绑定到其他 IP 地址,请指定该地址而不是localhost
(或对所有网络接口使用 0.0.0.0
)。