Linux 旋度:(7)不能';t连接到主机我的设置有什么问题?

Linux 旋度:(7)不能';t连接到主机我的设置有什么问题?,linux,shell,curl,Linux,Shell,Curl,运行命令时: $ curl http://localhost:9201 我得到这个错误: curl: (7) couldn't connect to host 接下来,当我运行带有详细标志的命令curl时,即: $ curl -v http://localhost:9201 它以错误告终: * About to connect() to localhost port 9201 (#0) * Trying ::1... Connection refused * Trying 127.

运行命令时:

$ curl http://localhost:9201
我得到这个错误:

curl: (7) couldn't connect to host
接下来,当我运行带有详细标志的命令
curl
时,即:

$ curl -v http://localhost:9201
它以错误告终:

* About to connect() to localhost port 9201 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

我真的不明白为什么会发生这种错误。我的设置有什么问题?如何修复此问题?

显然,您的服务器没有在端口
9201上侦听

您需要首先验证服务器是否已成功开始侦听指定端口。根据建议,您可以使用
netstat
命令来验证这一点

例如:

要列出所有
对及其状态和各自的过程:

$ netstat -anp
观察
本地地址
状态
PID/程序名
列,以识别您的进程及其指定的状态

要检查指定端口是否由进程使用,无论其状态如何:

$ netstat -anp | grep :9201
要确保端口已打开以进行侦听,请执行以下操作:

$ netstat -anp | grep LISTEN | grep :9201

您还可以使用REST客户端(例如)从GUI与web服务器交互。

您尝试连接的服务不可用是您应该进行的第一项检查。然而,在我的例子中,它正在运行,并得到了一个更奇怪的错误:

$ curl -i -X POST http://127.0.0.1:12345/command -d 'some JSON here'
curl: (7) Failed connect to 127.0.0.1:31280; Connection refused
为什么是错误的端口?!嗯,
man curl
确实描述了
-v
标志,所以让我们使用它:

$ curl -i -v -X POST http://localhost:12345/command -d 'some JSON here'
* About to connect() to proxy 127.0.0.1 port 31280 (#0)
*   Trying 127.0.0.1...
* Connection refused
* Failed connect to 127.0.0.1:31280; Connection refused
* Closing connection 0
curl: (7) Failed connect to 127.0.0.1:31280; Connection refused

现在,我们可以为自己没有安装代理而facepalm了。

另一个原因可能是
/etc/hosts
中的错误配置;如果没有类似的行

127.0.0.1 localhost
localhost
将不会解析为
127.0.0.1

在我的例子中,我无法打开Apache提供的主机

我的卷发是

root@myserver:~# curl -v -k --compressed -H 'Host: www.mysite.com' 

http://localhost/
* About to connect() to localhost port 80 (#0)
*   Trying ::1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
这一反应没有引起注意

*   Trying 127.0.0.1... connected

/etc/hosts
中添加
127.0.0.1 localhost
修复了该问题。

运行“netstat-pan”,检查端口9201是否正确listening@yudongshen9201未侦听。我该怎么办?启动web服务器,如果失败,请检查其日志,然后尝试修复。