我一直拿吊机韩国来反代朋友的emby来自己看,前段时间吊机韩国加了ipv6,忽然发现反代变慢了许多,网页都要好几秒才能打开。排查了下机子问题,发现机子到本地和美国的速度都很正常,能跑满百兆,故怀疑是ipv6的问题。于是我修改/etc/gai.conf把里面的precedence ::ffff:0:0/96 100注释删掉了,curl了下ip.sb,已经默认是v4了,可是访问还是很慢。最后我怀疑是nginx的反向代理并不受系统优先级影响,所以上网找了下nginx反代关闭ipv6的方法。记录一下希望能帮到更多的人。

resolver 8.8.8.8 ipv6=off;
set $proxy_url {{要反代的地址}};
#PROXY-START/
client_max_body_size 5000M;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For '$proxy_add_x_forwarded_for';
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
    proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
    proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
    proxy_cache off;
    proxy_redirect off;
    proxy_buffering off;
location / {
        proxy_pass $proxy_url;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_ssl_verify off;
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
        proxy_send_timeout 86400;
    }
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
    proxy_pass $proxy_url;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    expires 12h;
}
#PROXY-END/
Last modification:February 17, 2023
If you think my article is useful to you, please feel free to appreciate