Listen
语法:listen address:port [default [ backlog=num |rcvbuf=size|sndbuf=size|accept_filter=filter|deferred\bind ] ]
默认值:listen 80
Context:server
此指令指定了服务器接受请求的ip地址和端口号,可以只指定主机或端口,另外地址也可以是服务器名
e.g.
listen 127.0.0.1:8000
listen 127.0.0.1
listen 8000
listen *:8000
listen localhost:8000
如果只给出了地址,则使用默认端口80
若此指令使用了“default”参数,那么此指令所描述的server将成为address:port对的默认server。但如果没有“default”参数,则默认服务器就是第一个server,这个server由address:port描述。
含有“default”参数的listen指令,可以包含多个参数(default的参数),明确的讲是针对listen(2)和bind(2)
Backlog=num 指定调用listen(2)时的backlog参数。Backlog的默认值是-1
Rcvbuf=size 为listening socket 指定SO_RCVBUF参数
Sndbuf=size 为listening socket 指定SO_SNDBUF 参数
It works only to FreeBSD, it is possible to use two filters -- dataready and httpready. On the signal -HUP accept-filter it is possible to change only in the quite last versions FreeBSD: 6.0, 5.4-STABLE and 4.11-STABLE.
Deffered 指定在linux系统上在TCP_DEFER_ACCEPT帮助下使用延缓的accept(2)
indicates to use that postponed accept(2) on Linux with the aid of option TCP_DEFER_ACCEPT.
Bind 指出有必要使得为address:port对的bind(2)独立出来
The fact is that if are described several directives listen with the identical port, but by different addresses and one of the directives listen listens to on all addresses for this port (*:port), then nginx will make bind(2) only to *:port. It is necessary to consider that in this case for determining the address, on which the connections arrive, is done the system call getsockname(). But if are used parameters backlog, rcvbuf, sndbuf, accept_filter or deferred, then it is always done separately for this pair of address:port bind(2).
listen 127.0.0.1 default accept_filter=dataready backlog=1024;
联系客服