不同文件夹中的Nginx Yii2配置 [英] Nginx Yii2 configuration in different folders
问题描述
我在为yii2基本应用配置nginx服务器时遇到问题.
I faced with problem in configuring nginx server for yii2 basic app.
这是我的服务阻止文件:
Here is my service block file :
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将提供另一个文件夹中的文件.
My project located in another folder "another_folder". And i want that when user goes to url : http://ip/fetch files nginx will serve files from another folder.
我的错误日志文件返回我:
My error log file returns me :
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
然后哥哥显示: 未指定输入文件.
And brother shows : No input file specified.
您能帮我解决这个问题吗?
Can you give help me with this issue?
谢谢!
推荐答案
在您的注释中,任何以/fetch
开头的,与别名路径中的静态文件都不匹配的URI,都应重定向到/fetch/index.php
. /p>
Further to your comment, any URI beginning with /fetch
that does not match a static file within the aliased path, should be redirected to /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_files
与alias
一起使用.
We avoid using try_files
with alias
because of this long term issue.
有关使用<的信息,请参见此警告 c4>.
这篇关于不同文件夹中的Nginx Yii2配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!