我想要一个http://example.com/foobar返回的请求http://example.com/foobar.jpg。(或 .gif、.html、.whatever)
这与 Apache MultiViews 无关,在 Nginx 中似乎同样容易。这个问题似乎暗示它会像try_files $uri $uri/ index.php;在 location 块中一样简单,但这不起作用。
try_files $uri $uri/ =404;不起作用,try_files $uri =404;或者try_files $uri.* =404;在我的location / {块和匹配图像的正则表达式之间移动它也不起作用。
至关重要的是,try_files $uri.jpg =404; 确实有效,但仅适用于 .jpg 文件,如果我在一个位置块中使用多个 try_files 规则,则会引发配置错误!
当前server {区块:
server {
listen 80;
server_name example.org www.example.org;
access_log /var/log/nginx/vhosts.access.log;
root /srv/www/vhosts/example;
location / {
root /srv/www/vhosts/example;
}
location ~* \.(?:ico|css|js|gif|jpe?g|es|png)$ {
expires max;
add_header Cache-Control public;
try_files $uri …Run Code Online (Sandbox Code Playgroud)