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时:nginx http://ip/fetch 文件将提供来自另一个文件夹的文件。

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

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;
    }
}

由于这个长期问题,我们避免将try_filesalias一起使用。

请参阅有关使用if的注意事项。

最新更新