SO_REUSEPORT

Maxim Dounin mdounin at mdounin.ru
Wed Jun 10 12:53:16 UTC 2015


Hello!

On Wed, Jun 10, 2015 at 11:46:49AM +0200, basti wrote:

> Hello,
> Ihave rebuild nginx 1.9.1 from source to use SO_REUSEPORT on my wheezy
> install with kernel 3.16 (from backports).
> (packages from http://nginx.org/packages/mainline/debian/has not include
> SO_REUSEPORT)
> 
> Some errors are still present:
> 
> [emerg] 19351#19351: duplicate listen options for 0.0.0.0:80 in ...
> 
> Is there a way to use "reuseports" for multiple locations?
> How can I test if it works for a special location?
> Is there a header send or something else? Or is the only way to compare
> "stress test" like siege?

Much like all other listening socket options, "reuseport" have to 
be specified only once, usually in a default server for a listen 
socket in question.  That is, if you have many servers listening 
on port 80, you should write something like:

    server {
        listen 80 reuseport;
        server_name default.example.com;
        ...
    }

    server {
        listen 80; # no options here
        server_name virtual.example.com;
        ...
    }

To check if reuseport actually works just check how many listening 
sockets were created - normally there will be just one, 
but with reuseport you'll see multiple listening sockets, one for 
each of nginx worker processes.  Something like "ss -nlt" should 
show listening sockets on Linux.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list