Nginx上的Jekell博客博客

问题描述 投票:0回答:1

我正在尝试在nginx上提供jekyll博客。构建目录中的文件应通过以下路径访问:

  - index.html -> /
  - 1.0/
    - index.html -> /1.0/
    - foo/
        a.html   -> /1.0/foo/a/
        b.html   -> /1.0/foo/b/
        c.html   -> /1.0/foo/c/
    - bar/
        1.html   -> /1.0/bar/1/
        2.html   -> /1.0/bar/2/

我尝试在nginx中使用try_files指令,但尽管文件可用,但它始终调用后备。这是配置:

location ~* ^(.+)/$ {
  try_files $uri /$1/index.html /$1.html =404;
}

如果删除404后备广告,则仅适用于最后一个值。

所以我的问题是:配置nginx来提供这样的静态文件的最佳方法是什么?

nginx jekyll static-files
1个回答
0
投票

如果删除404后备广告,则仅适用于最后一个值。

这是因为try_files指令的最后一个参数应该是HTTP错误代码或URI(如果找不到该文件,请尝试使用该URI)。在您的情况下,nginx假定它是一个URI。

尝试一下:

try_files

如果要处理类似于location ~ ^(?<path>/.*/)(?<file>[^/]+)/$ { try_files $uri $path$file.html $uri/ =404; } http://example.com/1.0/foo/a请求,请将正则表达式更改为http://example.com/1.0/foo/a/

© www.soinside.com 2019 - 2024. All rights reserved.