server { listen *:80 default_server; server_name lidihuo.co; return 200 "Hello from lidihuo.co"; } server { listen *:80; server_name nikita.co; return 200 "Hello from nikita.co"; } server { listen *:81; server_name deep.co; return 200 "Hello from deep.co"; }
IP 上的服务器列表: 端口,带有匹配指令,即 server_name。
IP 上的服务器列表: 端口,带有default_server 标志;
IP 上的服务器列表: 端口,已定义的第一个。
如果没有匹配项,则拒绝连接。
Request to nikita.co:80 => "Hello from nikita.co" Request to www.nikita.co:80 => "Hello from lidihuo.co" Request to deep.co:80 => "Hello from lidihuo.co" Request to deep.co:81 => "Hello from nikita.co" Request to nikita.co:81 => "Hello from deep.co"
server_name lidihuo.co www.lidihuo.co; # exact match server_name *.lidihuo.co; # wildcard matching server_name lidihuo.*; # wildcard matching server_name ~^[0-9]*\.lidihuo\.co$; # regexp matching
确切名称;
以星号开头的最长通配符名称,例如"*examples.org",
以星号结尾的最长通配符名称,例如"mail.*";
首先匹配正则表达式。
server_name .lidihuo.co;
的缩写
server_name lidihuo.co www.lidihuo.co *.lidihuo.co;
listen 127.0.0.1:80; listen 127.0.0.1; # port :80 is used by default listen *:81; listen 81; # all ips are used by default listen [::]:80; # IPv6 addresses listen [::1]; # IPv6 addresses
listen unix:/var/run/Nginx.sock;
listen localhost:80; listen netguru.co:80;