不同文件夹下的Nginx Yii2配置 [英] Nginx Yii2 configuration in different folders
问题描述
我在为 yii2 基本应用程序配置 nginx 服务器时遇到问题.
I faced with problem in configuring nginx server for yii2 basic app.
这是我的服务块文件:
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
.
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.
请参阅此注意事项关于使用<代码>如果代码>.
这篇关于不同文件夹下的Nginx Yii2配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!