【问题标题】:Strange webserver issue奇怪的网络服务器问题
【发布时间】:2013-03-12 19:05:45
【问题描述】:

我的操作系统:Ubuntu 12.10 Web服务器环境为:Nginx + PHP-FPM

安装基于on this tutorial

这里是网站的 nginx 配置文件

server {
set $host_path "path_to_website";

server_name  website.local;

root $host_path;
set $yii_bootstrap "index.php";

charset utf-8;
index index.php index.html;

log_not_found off;

location / {
    index  index.html $yii_bootstrap;
    try_files $uri $uri/ /$yii_bootstrap?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) {
    deny  all;
    }

    #avoid processing of calls to unexisting static files by yii
    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    try_files $uri =404;
}


location ~ \.php$ {
    fastcgi_split_path_info  ^(.+\.php)(.*)$;
    #let yii catch the calls to unexising PHP files
    set $fsn /$yii_bootstrap;
    if (-f $document_root$fastcgi_script_name){
        set $fsn $fastcgi_script_name;
    }
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny  all;
}

}

顺便说一句,这个配置是optimized for Yii framework

问题是,当我尝试进入网站时,出现以下错误:

File not found. 

当我打开 nginx error.log 文件时,我看到以下内容

    2013/03/22 23:36:45 [crit] 14388#0: *4 stat() "path_to_website" failed (13: Permission denied), client: 127.0.0.1, server: website.local, request: "GET / HTTP/1.1", host: "website.local"
2013/03/22 23:36:45 [crit] 14388#0: *4 stat() "path_to_website" failed (13: Permission denied), client: 127.0.0.1, server: website.local, request: "GET / HTTP/1.1", host: "website.local"
2013/03/22 23:36:45 [crit] 14388#0: *4 stat() "path_to_websiteindex.php" failed (13: Permission denied), client: 127.0.0.1, server: website.local, request: "GET / HTTP/1.1", host: "website.local"
2013/03/22 23:36:45 [error] 14388#0: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: website.local, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "website.local"

我 100% 确定网站的路径,并添加到主机文件 website.local。还有chown-ed 递归地递归整个父目录,网站所在的位置。

我不知道可能是什么问题。请帮我解决这个问题。我可以为任何想提供帮助的人提供远程访问权限。

注意

为了信心,我刚刚用这个path_to_website 替换了真实路径。就这样。这是真正的路径

【问题讨论】:

  • 为什么设置了$fsn却从不使用它?

标签: php linux ubuntu nginx webserver


【解决方案1】:
 set $host_path "path_to_website";

你需要定义你的 path_to_website 是什么:

即:/var/www/

  1. 打开终端

  2. 列表项

  3. cd 进入你的 www 目录的根目录
  4. 输入“pwd”,无论结果如何
  5. 将其输入 $host_path

【讨论】:

  • 2013/03/22 23:36:45 [crit] 14388#0: *4 stat() "path_to_website" 失败(13:权限被拒绝),客户端:127.0.0.1,服务器:网站.local, request: "GET / HTTP/1.1", host: "website.local" .. 它显示的是 path_to_website,而不是实际位置
  • 我刚刚用这个path_to_website 替换了真实的路径以获取信心。就这样。这是真正的路径
  • 该文件夹的权限是什么
  • 我给了命令 chmod 755,并从父文件夹开始递归地 chown -x
  • 如果你确定文件夹+主机信息是正确的。然后我认为将 ngnix 进程作为守护进程运行的用户没有访问权限。这会返回什么:ps aux | grep "nginx:工作进程"
【解决方案2】:

nginx 日志文件永远不会说谎。如果它说这是一个“权限被拒绝”错误,那么它就是。你需要

  • 确保该文件夹本身“path_to_website”对于用户 www-data 是可读的(根据您的屏幕截图,这是运行 nginx 的用户)。尝试此操作的一种方法是在终端中运行此命令:

     sudo -u www-data ls path_to_website
    

并查看是否拒绝 www-data 的权限或只是

   ls -la path_to_website

调查该路径的权限信息。

  • 用户 www-data 可能无法访问“path_to_website”的父文件夹。例如,如果您的 path_to_website 是“/var/www/mysite/”,那么 www-data 可能无法读取“/var”或“/var/www”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多