如何在 nginx 中仅提取文件名(basename)
你可以通过在正则表达式命名组中捕获它来轻松地仅提取文件名(例如 https://domain.com/directory/myfile.txt 的 myfile.txt):
nginx_request_basename.conf
location ~ ^/(?P<request_basename>[^/]+)$ {
# TODO:在此添加你的代码 - 你可以使用 $request_basename!
}有关用法示例,请参见我之前关于nginx:使用 Content-Disposition 强制整个目录的文件下载的文章。
Check out similar posts by category:
Nginx
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow