私はこの奇妙な動作に直面しましたが、今日は原因を見つけることができませんでした。私はMacOS Sierraを使用しています。Node.js/Expressがlocalhostからの接続を受け付けないのはなぜですか?
私はこのコード(エクスプレス)があります。
app.server.listen(config.port, config.address, function() {
logger.info('app is listening on', config.address + ':' + config.port);
});
をそして、それは私がcurl
しようとすると、それが失敗したどのようにこれまで、
app is listening on 127.0.0.1:5000
印刷します。 127.0.0.1
にそれの解決を確認する
$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
だから私ピングはlocalhost:
$ curl http://localhost:5000/api/ping
curl: (56) Recv failure: Connection reset by peer
は、私は私のhostsファイルをチェックし
$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.061 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.126 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.135 ms
^C
--- localhost ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.061/0.107/0.135/0.033 ms
を私は、もう一度試していますが、
$ curl http://localhost:5000/api/ping
curl: (56) Recv failure: Connection reset by peer
を失敗しました
今私は私達に挑戦する代わりにe 127.0.0.1
とvoila、それは動作しますか?
$ curl http://127.0.0.1:5000/api/ping
pong
何が問題なのですか。
/etc/hostsファイルの内容を投稿してもよろしいですか? 'localhost'が間違ってマッピングされているようです。これはこの種のエラーを引き起こす可能性があります。 –
ネットワークアダプタでIPv6が有効になっていますか? CurlがIPv6を介して接続しようとしている可能性がありますが、サーバーはそのアドレスでリッスンしていません。 –
ホストファイルが追加されました – mitchkman