Nginx:带有$args的别名和try_files

前端之家收集整理的这篇文章主要介绍了Nginx:带有$args的别名和try_files前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参见英文答案 > How can I get around using alias in nginx?                                    1个
当我尝试在位置/ api / v1使用带有?$args的try_files时,我得到错误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;
        }
    }
}
最佳答案
There are issues当你一起使用try_files和alias指令时.

作为解决方法,删除别名并使用root和重写.

原文链接:https://www.f2er.com/nginx/435220.html

猜你在找的Nginx相关文章