bluecodr’s diary

忘れがちなTipsの備忘録。主にUbuntuやRailsについて記載。

nginxで"111: Connection refused"が出る場合の対処方法

さくらクラウド(Ubuntu14.04)でnginx, rails unicornを利用した際に以下の様なログが出る場合がある

2015/01/01 12:12:12 [error] 8652#0: *228 connect() failed (111: Connection refused) 
while connecting to upstream, client: 111.111.111.111, server: 222.222.222.222, 
request: "GET /entries HTTP/1.1", upstream: "http://[::1]:3999/entries", 
host: "222.222.222.222", referrer: "http://222.222.222.222/entries/1"

この場合、nginxにて用いている"localhost"がipv6になっている為Connection refusedになっている。

/etc/hostsを編集

before

::1     localhost ip6-localhost ip6-loopback

after

::1     ip6-localhost ip6-loopback