Skip to content

Location Selection

Sanne Albreghs edited this page Sep 19, 2022 · 1 revision

Location Serving

The location directive allows to route request to the correct location within the file system. The directive is used to tell where to look for a resource by including files and folders while matching a location block against an URI.

The location block

The location block will be placed within a server block. The nginx location block works with a modifier, which our webserv does not do. The syntax of our location block is:

location [URI] {
    ...
}

Within the location block the following directives can be set:

Location matching

The location block will match any request starting with what is defined in [URI]. If multiple location blocks match the URI, the longest match will be chosen. For example:
Requested URI: /hello.txt

location / {
}

location /hey {
}

location /hello {
}

location /hello.t {
}

The location blocks 1 3 and 4 all match, but as 4 has the longest match, this will be the location block that will handle the request.

Location Selection Class