Nginx notes – (1) – Comparison between alias and root

Time:2021-10-20

Use separatelyaliasAnd root configuration accessb.html

1.1 root – > URL is added to root and located

Root configuration in nginx:

location ^~ /app1/ {
    root /web;
}

#Access: localhost / app1 / b.html

b. HTML directory on the server: / Web / app1 / b.html

  1. What is the URL when accessing?

    localhost/app1/b.html

  2. Where does the access URL map to?

    /app1/b.html:

    Root + location mapping: / Web / app1 / b.html

1.2 alias – > URL replaced by alias

Alias configuration in nginx:

location ^~ /app2/ {
    alias /web;
}
b. HTML Directory: / Web / b.html
Visit: localhost / app2 / b.html
Conclusion: equivalent to replacement

b. HTML directory on the server: / Web / b.html

  1. What is the URL when accessing?

    Localhost / app2 / b.html (URL similar to above)

  2. Where does the access URL map to?

    /app2/b.html:

    Alias replace location mapping: / Web / b.html

1.3 summary

Alias: the URI of location will be replaced by that of alias;

Root: the URI of location will be appended to the root and connected;