Location Matches
Nginx configuration
events {
}
http {
server {
listen 80;
server_name nginx-handbook.test;
location =/agatha {
return 200 "Miss Marple.\nHercule Poirot.\n";
}
}
}
- Visit localhost/agatha, you will get this response
# HTTP/1.1 200 OK
# Server: nginx/1.18.0 (Ubuntu)
# Date: Wed, 21 Apr 2021 15:59:07 GMT
# Content-Type: text/plain
# Content-Length: 29
# Connection: keep-alive
# Miss Marple.
# Hercule Poirot.
- Adding an = sign before the location URI will instruct NGINX to respond only if the URL matches exactly. Now if you send a request to anything but /agatha, you'll get a 404 response.