Nginx Yii2configuration在不同的文件夹中

我在为yii2基本应用程序configurationnginx服务器时遇到了问题。

这是我的服务块文件:

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 

和兄弟显示:没有指定input文件。

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

谢谢!

除了您的评论,任何以/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; } } 

由于这个长期问题,我们避免使用alias try_files

请参阅有关使用if 警告 。