首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >禁用nginx IPv6中的proxy_pass

禁用nginx IPv6中的proxy_pass
EN

Server Fault用户
提问于 2013-07-30 13:53:00
回答 5查看 59K关注 0票数 33

我的服务器没有IPv6附件。

但是,当我使用Nginx proxy_pass与IPv4和IPv6一起上行时,有时它尝试使用IPv6发送传出请求:

代码语言:javascript
运行
复制
2013/07/30 00:25:06 [error] 1930#0: *1482670 connect() to [AAAA:BBBB:C:DDD:E:F:GGG:HHH]:443 failed (101: Network is unreachable) while connecting to upstream, client: AA.BB.CC.DD, server: example.com, request: "GET /download/file HTTP/1.0", upstream: "https://[AAAA:BBBB:C:DDD:E:F:GGG:HHH]:443/download/file", host: "example.com"

如何在IPv6中禁用proxy_pass中的传出请求?

nginx.conf:

代码语言:javascript
运行
复制
upstream download {
  server download.example.com:443;
  keepalive 8;
}

location /download {
  proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
  proxy_set_header      Connection "";
  proxy_ignore_headers  X-Accel-Redirect;
  proxy_http_version    1.1;
  resolver              8.8.8.8;
  resolver_timeout      5s;
  proxy_pass            https://download;
}

nginx -V:

代码语言:javascript
运行
复制
nginx version: nginx/1.4.2
built by gcc 4.7.2 (Debian 4.7.2-5)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-z,relro --with-ipv6

操作系统: Debian Wheezy

代码语言:javascript
运行
复制
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 GNU/Linux

ip a

代码语言:javascript
运行
复制
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 6c:62:6d:7a:ea:af brd ff:ff:ff:ff:ff:ff
    inet XXX.XXX.XXX.XXX/27 brd XXX.XXX.XXX.XXX scope global eth0
EN

回答 5

Server Fault用户

发布于 2016-08-15 15:25:03

看起来有一个解决方案,因为nginx >= 1.5.8:

代码语言:javascript
运行
复制
 resolver 8.8.8.8 ipv6=off;

您可以在这里找到更多信息:http://nginx.org/en/docs/http/ngx_http_核心_module.html

票数 28
EN

Server Fault用户

发布于 2019-08-23 23:26:10

在将resolver用于https url时,使用proxy_pass并不适用于我。我不得不修改系统。

  1. /etc/sysctl.conf. net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 net.ipv6.conf.eth0.disable_ipv6 = 1 net.ipv6.conf.eth1.disable_ipv6 = 1 net.ipv6.conf.eth2.disable_ipv6 = 1 net.ipv6.conf.eth3.disable_ipv6 = 1中添加以下行
  2. sysctl -p重新启动系统。
  3. sudo nginx -s reload重新启动nginx。
票数 3
EN

Server Fault用户

发布于 2022-04-07 04:55:32

对于本地主机,我对fastcgi_pass也有同样的问题。在这种特殊情况下(即,如果只转发到localhost),可以使用

代码语言:javascript
运行
复制
fastcgi_pass 127.0.0.1:9000;

而不是

代码语言:javascript
运行
复制
fastcgi_pass localhost:9000;
票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/527317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档