All Nginx URIs begin with a leading /
.
Use location =
syntax to exactly match a single URI. See this document for details.
There are a number of ways to select a single file from within a location
block. The most explicit is to specify it as the first parameter of a try_files
statement. See this document for details.
For example:
root /var/www/my-site/my-site.com;
location = /term-of-service.txt {
try_files /term_of_service/term_of_service.txt =404;
}
location = / {
try_files /landing_page/scratch.html =404;
}
If you want treat the landing_page
directory as the document root, the term_of_service.txt
file would be outside the document root and therefore require its own root
statement inside the location
block.
For example:
root /var/www/my-site/my-site.com/landing_page;
location / {
index scratch.html;
try_files $uri $uri/ =404;
}
location = /term-of-service.txt {
root /var/www/my-site/my-site.com/term_of_service;
try_files /term_of_service.txt =404;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…