8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[解決済み]nginx の resolver で ipv6 を無効にする

Posted at

nginx を、外部の画像サーバのリサイズとかキャッシュに使用していて、
proxy_pass $url で動的に色々な画像サーバのURLを指定しています。

不具合の現象

nginx ver 0.8.5 を 1.7 系にアップしたら、
特定のURLのみ ipv6 を引いて来てしまい、3回中1回位の確率で、upstream: に ipv6 の ip が指定されて、接続できない事がありました。

下記のようなログを大量に出力されてた。

2016/01/06 00:00:00 [alert] 721#0: *156131 socket() failed (97: Address family not supported by protocol) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /resize?width=100&height=100&url=http://example.com/example_image.jpg HTTP/1.0", upstream: "http://[2404:6800:400a:805::2010]:80/img/gaikan/N941/N9414697/N941469780000020120T.jpg", host: "127.0.0.1:8080"

特定 URL が下記のような AAAA を返すのが原因の様でした。

[root@nginx]$ dig storage.l.googleusercontent.COM @192.168.1.1 any
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.6 <<>> storage.l.googleusercontent.COM @158.205.237.131 any
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43948
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;storage.l.googleusercontent.COM. IN	ANY

;; ANSWER SECTION:
storage.l.googleusercontent.COM. 82 IN	AAAA	2404:6800:400a:806::2010
storage.l.googleusercontent.COM. 82 IN	A	216.58.196.240

;; Query time: 3 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Wed Jan  6 22:11:35 2016
;; MSG SIZE  rcvd: 93

そこで nginx.conf の resolver の設定に "ipv6=off" にして、無事解決しました!

server {
    listen 80;
    server_name localhost;
    resolver 192.168.1.1 ipv6=off;

参考ページ

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?