Nginx 别名忽略最后一个字母

标签 nginx alias

这让我很紧张,因为它没有意义。我想定义一个别名规则,但 Nginx 忽略了最后一个字母并由于某种原因尝试提供错误的文件。

配置:

server {
    server_name domain.com;
    listen 666;

    root /srv/http;
    autoindex on;

    location /subdir {
            alias /srv/http/someplace;
            index index.php;

            try_files $uri $uri/ /index.php?$args;
    }
}

但是我得到的错误是2014/05/28 17:46:25 [error] 13937#0: *221 opendir() "/srv/http/someplac"failed (2: No such file or目录),客户端:123.234.123.234,服务器:domain.com,请求:“GET/HTTP/1.1”,主机:“domain.com:666”

为什么它不读取完整路径?是否有像 not_ignore_last_letter 这样的指令我必须打开?

最佳答案

有一个long standing (try_files & alias) bug在 Nginx 中。

要解决此问题,您可以使用 root 指令再次设置或 fastcgi_param 中的 SCRIPT_FILENAMESCRIPT_NAME .

root 指令示例

location /subdir {
    root /srv/http/someplace;
    index index.php;

    try_files $uri $uri/ /index.php?$args;

    # the usual stuff
}

自定义$document_root$fastcgi_script_name示例

location ~ ^/subdir /(.*)$ {
    set $custom_script_name         "/subdir/index.php";
    set $custom_document_root       "/srv/http/someplace";
    set $custom_bootstrap_script    "/index.php";
    try_files "" @customphp;
}

location @customphp {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    include fastcgi_params;

    fastcgi_param   SCRIPT_FILENAME     $custom_document_root$custom_bootstrap_script;
    fastcgi_param   SCRIPT_NAME         $custom_script_name;

    # the usual stuff
}

关于Nginx 别名忽略最后一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921479/

相关文章:

Nginx - 使用/子文件夹重定向反向代理 Ghost 博客

php - PHP 命名空间自动加载是否必须使用文件夹?

ruby-on-rails - 在 Rails 中使用数据库列别名时出现 NoMethodError

sql - MySQL:可能在 AS 别名中有通配符?

c++ - 如何为单例函数创建别名?

http - php-fpm 每天停止多次

javascript - 单个服务器中的多个 ssl 域

nginx - 使用cjson在lua中获取json值

nginx - 在特定时间交付 503 服务不可用

Neo4J 返回带有空格的列别名 (AS) 名称,这可能吗?