V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
gyzit
V2EX  ›  服务器

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

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

    /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 being 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  
       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   ·   我们的愿景   ·   实用小工具   ·   1069 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 23:52 · PVG 07:52 · LAX 16:52 · JFK 19:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.