nginx-02

nginx에서 wildcard를 쓰고 싶어서 한번 알아 봤다.

server {
    listen       80;
    server_name  *.test-nginx.com;

    location / {
        root   /usr/share/nginx/html;
        index  ccc.html ccc.htm;
    }
}

server {
    listen       80;
    server_name  www.test-nginx.com;
    location / {
        root   /usr/share/nginx/html;
        index  www.html www.htm;
    }
}

이상태면 *가 먼저 만나서 ccc가 나오는거 아닐까?

테스트해 보았는데 www가 나왔다. * 는 우선순위가 제일 마지막으로 밀리는듯 하다.

http://nginx.org/en/docs/http/server_names.html

When searching for a virtual server by name,
if name matches more than one of the specified variants,
e.g. both wildcard name and regular expression match,
the first matching variant will be chosen,
in the following order of precedence:

1.exact name
2.longest wildcard name starting with an asterisk, e.g. “*.example.org”
3.longest wildcard name ending with an asterisk, e.g. “mail.*”
4.first matching regular expression (in order of appearance in a configuration file)

위와 같은 순서로 된다고 한다.

teamsmiley's profile image

teamsmiley

2021-04-19 00:00

Read more posts by this author