大网数据广告活动
服务器运维问答

Nginx duplicate listen options for [::]:80 error

· 52CE 我爱测

When I run the command to test my configuration I get an error saying there are multiple duplicates for [::]:80 . Before that I had an issue with duplicate multiple default servers. When I had the issue with multiple default serv…

问题原文

原帖链接 · ztmcoder · CC BY-SA 3.0

When I run the command to test my configuration I get an error saying there are multiple duplicates for [::]:80. Before that I had an issue with duplicate multiple default servers.

When I had the issue with multiple default servers, my file looked like this

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.php index.html index.htm;

server_name munki;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
    }

location /report {
    try_files $uri $uri/ =404;
    }

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

location /munki_repo/ {
    alias /usr/local/munki_repo/;
    autoindex off;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

To resolve that problem, I changed the configuration to:

server {
listen 80;
listen [::]:80 ipv6only=on;

root /usr/share/nginx/html;
index index.php index.html index.htm;

server_name munki;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
    }

location /report {
    try_files $uri $uri/ =404;
    }

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

location /munki_repo/ {
    alias /usr/local/munki_repo/;
    autoindex off;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

After the change I started getting a "duplicate options for [::]:80" error. I am not sure what I am doing wrong with this. This is my first time working with Nginx. Any ideas what the issue could be?

已采纳解答

原帖链接 · simlev · CC BY-SA 3.0

I'm creating an answer out of my earlier comment.

Please post the error message (nginx -t output) as it could contain some useful insight.

What nginx version are you running? Option ipv6only=on might not be needed anymore and on the contrary potentially create issues. I have this in my server block and it runs fine:

listen 80;
listen [::]:80;

Do you have any other server blocks you didn't post that might possibly conflict with eachother?


Explanation: let's read the current (1.13) nginx documentation:

ipv6only=on|off
this parameter (0.7.42) determines (via the IPV6_V6ONLY socket option) whether an IPv6 socket listening on a wildcard address [::] will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start.

This parameter is turned on by default means that you should not use ipv6only=on. It does not do any good and can potentially create problems (see next point).

It can only be set once means that if you have it more than once anywhere in your configuration (such as in different server blocks), it will throw an error: nginx: [emerg] duplicate listen options for [::]:80.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。