关于 Nginx 多站点配置 IPv6 访问的问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
gyzit
V2EX    服务器

关于 Nginx 多站点配置 IPv6 访问的问题

  •  
  •   gyzit 2016-05-31 05:40:47 +08:00 9435 次点击
    这是一个创建于 3501 天前的主题,其中的信息可能已经有所发展或是发生改变。

    /usr/local/nginx/conf/nginx.conf : ( Nginx Default 的配置文件)

     server { listen 80; listen [::]:80 ipv6Only=on; server_name _; } ... include vhost/*.conf; } 

    /usr/local/nginx/conf/vhost/xxx.conf

    server { ... listen 443 ssl http2 fastopen=3 reuseport; listen [::]:443 ssl http2 fastopen=3 reuseport ipv6Only=on; ... } ... server { listen 80; listen [::]:80 ipv6Only=on; server_name xxxx.com; location / { rewrite ^/(.*)$ https://xxx.com/$1 permanent; } } 

    service nginx reload

    提示错误: nginx: [emerg] duplicate listen options for [::]:80 in /usr/local/nginx/conf/vhost/xxx.conf:97

    请问我的配置错在哪里呢?我想在 IPv6 访问的时候也能重定向到 https 页面。

    12 条回复    2018-04-13 13:35:58 +08:00
    lslqtz
        1
    lslqtz  
       2016-05-31 06:23:45 +08:00 via iPhone
    我去 ttlsa 看了下,有--with-ipv6 吗? 我记得不加 ipv6Only=on 是同时监听 ipv6 和 ipv4 更简洁一些。
    gyzit
        2
    gyzit  
    OP
       2016-05-31 06:42:41 +08:00 via iPhone
    @lslqtz 有的,其实我测试过主站通过 ipv6 访问是没问题的。但就是重定向那里不行。

    还有一个原因是我用 nginx 内置了 Google Analytics ,用 ipv6only 是为了他在提交数据的时候准确。
    lslqtz2
        3
    lslqtz2  
       2016-05-31 06:47:02 +08:00
    listen [::]:80 default ipv6Only=on;
    这是我在 ttlsa 看到的,搜了搜发现只有几个英文贴。。
    gyzit
        4
    gyzit  
    OP
       2016-05-31 06:54:22 +08:00
    @lslqtz2 依然会有同样的错误,我之前也查过很多资料的,包括 Google 。发现很少网站有提到,所以才上来问问大家。
    lslqtz2
        5
    lslqtz2  
       2016-05-31 07:02:22 +08:00
    @gyzit 我也去查查。
    lslqtz2
        6
    lslqtz2  
       2016-05-31 07:03:12 +08:00
    @gyzit
    关键这句:[Because the first file has the ipv6Only=on option, the second file does not need it.]

    You can only specify options for the listen directive once per combination of host:port (see the documentation).

    The error is eing caused by this line in your second file:

    listen [::]:80 ipv6Only=on;
    Because the first file has the ipv6Only=on option, the second file does not need it.

    Changing the beginning of the second file to the following should fix the problem:

    server {
    listen 80;
    listen [::]:80;

    ...
    }
    gyzit
        7
    gyzit  
    OP
       2016-05-31 07:24:19 +08:00
    @lslqtz2 谢谢!

    我吧 `/usr/local/nginx/conf/vhost/xxx.conf` 最底下重定向的 server 的 ipv6Only=on 删了,好像就没问题了。

    但我还有个小疑问,他说 Because the first file has the ipv6Only=on option, the second file does not need it.

    我 80 端口的 ipv6Only=on 是在 nginx.conf ,那我下面 vhost 配置文件不加 ipv6Only=on ,这个没疑问。

    那我的 https 的 first file 是 xxx.conf ,那他怎么确定这份就是第一份呢?当我下次添加虚拟机的时候会出错吗?
    lslqtz2
        8
    lslqtz2  
       2016-05-31 07:32:02 +08:00
    @gyzit ipv6 没怎么碰过,不清楚。。反正我 ipv4 都是一个 server 块用一个 listen 80;的,这个估计得下次试试看。
    gyzit
        9
    gyzit  
    OP
       2016-05-31 07:55:39 +08:00
    @lslqtz2 对呀,就是 ipv4 可以一个 server 块 listen 80 不影响其他。但是 ipv6 就有点不一样。。。
    Showfom
        10
    Showfom  
    PRO
       2016-05-31 07:58:13 +08:00 via iPhone   1
    ipv6only 只能出现一次的啦
    gyzit
        11
    gyzit  
    OP
       2016-05-31 08:27:18 +08:00 via iPhone
    @Showfom 好的我懂了,谢谢。
    Joan114
        12
    Joan114  
       2018-04-13 13:35:58 +08:00
    你好,请问你的 ipv6 多站点配置成功了吗?
    我现在在配置多站点的时候遇到一个问题,都配置好测试的时候,发现提示这个
    This domain has no IPv6 DNS server, this may prevent some IPv6-only users from reaching it.

    请问这是什么原因导致的呢
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2322 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 12:16 PVG 20:16 LAX 04:16 JFK 07:16
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86