Nginx常见问题
Nginx多server优先级
在开始处理一个http请求时,nginx会取出header头中的Host变量,与nginx.conf中的每个server_name进行匹配,以此决定到底由哪一个server来处理这个请求,但nginx如何配置多个相同的server_name,会导致server_name出现优先级访问冲突。
案例
[root@lb01 code]# cat /etc/nginx/conf.d/server*.conf
server {
listen 80;
server_name localhost test1.com;
location / {
root /code/test1;
index index.html;
}
}
server {
listen 80;
server_name localhost test2.com;
location / {
root /code/test2;
index index.html;
}
}
server {
listen 80;
server_name localhost test3.com;
location / {
root /code/test3;
index index.html;
}
}
[root@lb01 conf.d]# cd /code/
[root@lb01 code]# ll
total 0
drwxr-xr-x 2 root root 6 Aug 10 00:31 test1
drwxr-xr-x 2 root root 6 Aug 10 00:31 test2
drwxr-xr-x 2 root root 6 Aug 10 00:31 test3
[root@lb01 code]# echo test1 > /code/test1/index.html
[