【发布时间】:2017-06-29 18:48:30
【问题描述】:
我在为 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 files 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/index.php位于/usr/share/nginx/html/another_folder/web/index.php还是/usr/share/nginx/html/another_folder/web/fetch/index.php? -
在这个文件夹中:/usr/share/nginx/html/another_folder/web/index.php
-
您需要使用
alias指令。见this answer。 -
谢谢。它解决了问题。但它无法在 yii2 中使用漂亮的 Url 找到 url。它再次在 /usr/share/nginx/html 文件夹中查找 index.php 文件
-
这是在
another_folder根目录中吗?漂亮的 URI 会以/fetch为前缀吗?
标签: nginx configuration-files yii2-basic-app nginx-location