1. 虚拟主机
Syntax: | server { ... } |
---|---|
Default: | — |
Context: | http |
Sets configuration for a virtual server. There is no clear separation between IP-based (based on the IP address) and name-based (based on the “Host” request header field) virtual servers. Instead, the listen directives describe all addresses and ports that should accept connections for the server, and the server_name directive lists all server names. Example configurations are provided in the “How nginx processes a request” document.
2. 主机名称
Syntax: | server_name |
---|---|
Default: | server_name ""; |
Context: | server |
Sets names of a virtual server, for example:
server { server_name example.com www.example.com; }
The first name becomes the primary server name.
Server names can include an asterisk (“*
”) replacing the first or last part of a name:
server { server_name example.com *.example.com www.example.*; }
Such names are called wildcard names.
3. 监听地址,端口以及协议
Syntax: | listen listen listen |
---|---|
Default: | listen *:80 | *:8000; |
Context: | server |
Sets the address
and port
for IP, or the path
for a UNIX-domain socket on which the server will accept requests. Both address
and port
, or only address
or only port
can be specified. An address
may also be a hostname, for example:
listen 127.0.0.1:8000; listen 127.0.0.1; listen 8000; listen *:8000; listen localhost:8000;
IPv6 addresses (0.7.36) are specified in square brackets:
listen [::]:8000; listen [::1];
UNIX-domain sockets (0.8.21) are specified with the “unix:
” prefix:
listen unix:/var/run/nginx.sock;
If only address
is given, the port 80 is used.
If the directive is not present then either *:80
is used if nginx runs with the superuser privileges, or *:8000
otherwise.