Nginx Yii2配置在不同的文件夹中

我遇到了为yii2基本应用程序配置Nginx服务器的问题.

这是我的服务块文件

server {
    listen       80 ;

    access_log /var/log/Nginx/access-server.log;
    error_log /var/log/Nginx/error-server.log;

    charset utf-8;

    location  /fetch {
            root /usr/share/Nginx/html/another_folder/web/;
            try_files $uri $uri/ /index.PHP$is_args$args;
    }

         location ~ \.PHP${
            fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.PHP;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

}

我的项目位于另一个文件夹“another_folder”中.
我希望当用户访问url:http://ip/fetch文件时,Nginx将提供来自其他文件夹的文件.

我的错误日志文件返回给我:

2017/02/11 12:38:52 [error] 4242#0: *12 FastCGI sent in stderr: "Unable to open primary script: /usr/share/Nginx/html/index.PHP (No such file or directory)" while reading response header from upstream

兄弟表示:
没有指定输入文件.

你能帮我解决这个问题吗?

谢谢!

最佳答案
对于您的注释,任何以/ fetch开头的URI与别名路径中的静态文件不匹配,都应重定向到/fetch/index.PHP.

location ^~ /fetch {
    alias /usr/share/Nginx/html/another_folder/web;

    if (!-e $request_filename) { rewrite ^ /fetch/index.PHP last; }

    location ~ \.PHP${
        if (!-f $request_filename) { return 404; }

        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
        fastcgi_pass   127.0.0.1:9000;
    }
}

由于this long term issue,我们避免将try_files与别名一起使用.

有关if的使用,请参阅this caution.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...