首页 > 代码库 > 关于nginx的server_name

关于nginx的server_name

server

{

  listen 80;
  server_name a.cjl.com;

  location /

  {
    echo $http_user_agent;
  }
}


server

{
  listen 80;
  server_name cjl.com;

  location /

  {
    echo $time_local;
  }
}

 

curl  -H "Host: b.cjl.com" http://127.0.0.1 输出了curl/7.29.0,也就是user-agent的值

原因是,server_name做了全字匹配,搜索不到,就执行了第一个listen 80的server下的location

如果这里想输出$time_local的值,应该把第二个server_name改写成server_name *.cjl.com

关于nginx的server_name