Nginx:别名和带有 $args 的 try_files

Nginx:别名和带有 $args 的 try_files

当我尝试使用try_files?$argslocation /api/v1出现错误 404。没有它,它就可以正常工作。有什么想法吗?


Nginx 配置

server {
    listen  80;
    server_name domain.com;

    index index.php;
    root  /home/ec2-user/dev.domain.com.br/webroot/default/web;

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

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $request_filename;
        include         fastcgi_params;
    }

    location /api/v1 {
        alias /home/ec2-user/dev.domain.com/webroot/apiv1/web;

        # Works, but don't parse args.
        try_files $uri /api/v1/index.php; ## << WORKING

        # Do not work. Error 404.
        try_files $uri /api/v1/index.php?$args; ## << ERROR

        location ~ \.php$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  $request_filename;
            include         fastcgi_params;
        }
    }
}

答案1

存在问题当您一起使用try_filesalias指令时。

作为一种解决方法,删除alias并使用rootrewrite

相关内容