
/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 页面。
1 lslqtz 2016-05-31 06:23:45 +08:00 via iPhone 我去 ttlsa 看了下,有--with-ipv6 吗? 我记得不加 ipv6Only=on 是同时监听 ipv6 和 ipv4 更简洁一些。 |
2 gyzit OP @lslqtz 有的,其实我测试过主站通过 ipv6 访问是没问题的。但就是重定向那里不行。 还有一个原因是我用 nginx 内置了 Google Analytics ,用 ipv6only 是为了他在提交数据的时候准确。 |
3 lslqtz2 2016-05-31 06:47:02 +08:00 listen [::]:80 default ipv6Only=on; 这是我在 ttlsa 看到的,搜了搜发现只有几个英文贴。。 |
4 gyzit OP @lslqtz2 依然会有同样的错误,我之前也查过很多资料的,包括 Google 。发现很少网站有提到,所以才上来问问大家。 |
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; ... } |
7 gyzit OP @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 ,那他怎么确定这份就是第一份呢?当我下次添加虚拟机的时候会出错吗? |
8 lslqtz2 2016-05-31 07:32:02 +08:00 @gyzit ipv6 没怎么碰过,不清楚。。反正我 ipv4 都是一个 server 块用一个 listen 80;的,这个估计得下次试试看。 |
9 gyzit OP @lslqtz2 对呀,就是 ipv4 可以一个 server 块 listen 80 不影响其他。但是 ipv6 就有点不一样。。。 |
10 Showfom PRO ipv6only 只能出现一次的啦 |
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. 请问这是什么原因导致的呢 |