nginx: error configuring “listen” in the server block

Today i stumbled upon an error while configurating my nginx test server. The config check resulted in this error message:

nginx: [emerg] duplicate listen options for 0.0.0.0:8080 in /usr/local/etc/nginx/extra/server_defaults.conf:1

My configuration consisted of following files:

# nginx.conf
worker_processes  1;
error_log  /var/log/nginx/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    index index.php index.html; # /index.php macht einen redirect
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/http_access.log main;
    error_log /var/log/nginx/http_error.log notice;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    server { # catch all
        listen 8080 accept_filter=httpready default_server;
        server_name *.example.com;
        rewrite ^ $scheme://example.com$request_uri redirect;
    }
    include vhosts/*.conf;
}

Here is an example vhost (i used the apache name for a server block :) )

    server {
        include extra/server_defaults.conf;
        server_name  example.com localhost;
        root /data/www/example.com/htdocs;
    }

And this is the “server default config”

listen       8080 accept_filter=httpready;
access_log /var/log/nginx/$host.access.log main;
location ~ /\.ht {
    deny  all;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
    access_log        off;
    expires           30d;
}
location ~ \.php$ {
    fastcgi_pass   unix:/tmp/php.sock;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/local/www/nginx-dist;
}

Now i figured out, that you are allowed to use any listen option once, for example only one accept_filter=httpready for a specific port like 8080. Now i use the option for the accept filter only inside the catch all server block and each configured server block can use the server defaults via include. This solved my problem. :)

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *


Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>