我最近用Nginx运行后端的东西,build立了Gollum 。
维基库存储在/path/to/root/todos (这是一个待办维基)。 然而,由于Gollum的工作方式,如果它在wiki上找不到页面,它会自动尝试创build一个(这很棒),但是会按如下所示重写URL:
http://www.domain.com/todos/foobar (不存在,将被创build)被重写为http://www.domain.com/create/foobar 。 现在,除非我为Gollum在自己的指令中使用的每个可能的uri单独设置一个条目,否则我们会在这里得到一个404错误。
为了避免这种情况,我将下面的内容添加到了我的nginxconfiguration中:
“`
location / { index index.php; try_files $uri /$uri /todos/$uri; }
“`
这工作,但它不会接受索引。 如果我直接进入domain.com/index.php ,我可以按照预期查看索引页面。 但是,直接转到网站( domain.com ),而是redirect到wiki的索引。 ( domain.com/create/home )。 我不明白这个行为,因为如果找不到原始的$ uri,并且index.php存在,它只能被路由到to-dos(这是对Gollum端口的proxy_pass指令)。
我在这里做错了什么? 这似乎是一个简单的问题,但这对我来说没有任何意义。
任何援助将不胜感激。
我刚刚发现这个页面时,有相同的问题,≈2年后。
我的解决scheme不涉及任何nginx黑客,但使用gollum中的选项标志。 --base-path ,应该照顾这个问题。 尝试实例化gollum:
$ gollum /path/to/root/todos/ --base-path todos
如果只在todo目录中find一个不存在的URI,则使得一个location /todos/ block包含try_files指令,因为您正在执行redirect。 一般build议将index指令放在服务器模块中,如果不同的位置模块不同的话。 (虽然这与这个问题无关)
server { ............. ............. index index.php; location /todos/ { try_files $uri $uri/ /create/$uri; } ............ ............ }
在您的configuration中,try_files /$uri的第二个参数是没有意义的,除非您尝试将http://www.domain.com/todos/foobarredirect到http://www.domain.com/foobar 。 后面的正斜线表示一个目录,而前面的斜线正好表示根级文件/目录。