【问题标题】:try_files directive for multiple grav installations用于多个重力安装的 try_files 指令
【发布时间】:2017-02-16 07:31:31
【问题描述】:

起初我将grav安装到nginx服务器的子目录中,它工作正常:cadoankitovua.com/blog

配置文件:

server {
    listen 80;
    server_name cadoankitovua.com www.cadoankitovua.com *.cadoankitovua.com;
    root /home/grav/web/public/;

    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /blog/index.php?_url=$uri&$query_string;
    }
    location ~ \.php$ {
        include /opt/local/etc/nginx/fastcgi.conf;
        fastcgi_pass 127.0.0.1:9000;
    }
}

然后,我将 grav 的相同副本安装到 /text 目录,并尝试以我所知道的许多不同方式修改 conf 文件。没有任何作用。

我有两个问题:

  1. 如何编辑 conf 文件以使 grav 同时在 /blog 和 /text 目录上工作?

  2. 一般来说,如果我将它们安装在许多子级目录中,我如何使许多 (>2) 个 grav 安装工作?

提前致谢。

【问题讨论】:

    标签: nginx grav


    【解决方案1】:

    我对重力一无所知,但你可以先添加一个location /text 块:

    server {
        listen 80;
        server_name cadoankitovua.com www.cadoankitovua.com *.cadoankitovua.com;
        root /home/grav/web/public;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /blog/index.php?_url=$uri&$query_string;
        }
        location /text {
            try_files $uri $uri/ /text/index.php?_url=$uri&$query_string;
        }
        location ~ \.php$ {
            include /opt/local/etc/nginx/fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
        }
    }
    

    编辑:一般的解决方案是使用带有重写语句的命名位置,例如:

    location / {
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^(/[^/]+) $1/index.php?_url=$uri&$query_string last;
        rewrite ^ /blog/index.php?_url=$uri&$query_string last;
    }
    

    【讨论】:

    • 这是我尝试的第一件事(没有 /text),但没有成功。现在我看到了你的版本:) 我刚试过。它就像一个魅力。谢谢你。第二个问题呢?
    • 到目前为止,通用的可以使用 2 个原始 /blog 和 /text。我添加了 /foo 和 /bar。这两个新的不行。我删除了 2 个新的并将名称 /text 更改为 /foo 或 /foo1。他们会工作的。我必须尝试更多不同的组合才能理解它。我会在这里报告更多。 :) 谢谢。非常感谢:)
    • 我将正则表达式 ^(/[^/]+) 解释为:以一个斜杠开头,然后是一个或多个除斜杠之外的任何字符。对吗?
    • 是的。唯一不匹配第一个rewrite 的URI 将是一个单独的/,这将导致第二个rewrite 被执行。
    • 如果没有第二个rewrite会怎样?
    猜你喜欢
    • 2018-12-19
    • 2013-06-25
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2017-05-28
    • 2013-07-21
    • 1970-01-01
    • 2014-10-08
    相关资源
    最近更新 更多