AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 459237
Accepted
F21
F21
Asked: 2012-12-19 21:03:31 +0800 CST2012-12-19 21:03:31 +0800 CST 2012-12-19 21:03:31 +0800 CST

Nginx + PHP - 没有为 1 个服务器块指定输入文件。其他服务器块工作正常

  • 772

我正在运行带有 nginx 1.2.6 的 Ubuntu Desktop 12.04。PHP 是 PHP-FPM 5.4.9。

这是我的相关部分nginx.conf:

http {
    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

       server_name testapp.com;
       root /www/app/www/;
       index index.php index.html index.htm;

       location ~ \.php$ {

        fastcgi_intercept_errors on;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
       }
    }

    server {
        listen       80  default_server;
        root /www
        index index.html index.php;

        location ~ \.php$ {
          fastcgi_intercept_errors on;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
        }
    }
}

相关位来自php-fpm.conf:

; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever 
;       possible. However, all PHP paths will be relative to the chroot
;       (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot = 

; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = /www

在我的主机文件中,我重定向了2 个域:testapp.com和.test.com127.0.0.1

我的网页文件都存储在/www.

从上面的设置来看,如果我访问test.com/phpinfo.phpand test.com/app/www,一切都会按预期进行,并且我会从 PHP 获得输出。

但是,如果我访问testapp.com,我会得到可怕的No input file specified.错误。

所以,在这一点上,我拉出日志文件看看:

2012/12/19 16:00:53 [error] 12183#0: *17 FastCGI sent in stderr: "Unable to open primary script: /www/app/www/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: testapp.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "testapp.com"

这让我很困惑,因为我检查了一遍又一遍,/www/app/www/index.php确实存在!这也通过有效的事实得到验证,test.com/app/www/index.php这意味着文件存在并且权限正确。

testapp.com为什么会发生这种情况?仅v-host出现故障的根本原因是什么?


只是对我的调查的更新:

我已经评论出来并chroot缩小问题范围chdirphp-fpm.conf

如果我删除location ~ \.php$块testapp.com,那么 nginx 将向我发送一个包含 PHP 代码的 bin 文件。这意味着在 nginx 方面,一切都很好。

问题是在将文件传递给 PHP-FPM 时一定有什么东西破坏了文件路径。

default_server话虽如此, v-host 可以正常工作是很奇怪的,因为它的根是/www,而 v-host 却不起作用,testapp.com因为根是/www/app/www.

nginx
  • 2 2 个回答
  • 5886 Views

2 个回答

  • Voted
  1. Best Answer
    F21
    2012-12-20T17:54:01+08:002012-12-20T17:54:01+08:00

    问题解决了。

    在我的php.ini,我有:

    doc_root = /www;
    

    这意味着所有 php 请求都会/www添加到文件的开头,这会导致问题。我也已经评论了 outchroot和chdirin,php-fpm.conf因为它们还会在文件路径的开头添加额外的位。

    到目前为止一切正常,但是,我将进行更多研究以获取chroot并chdir努力确保安装安全。

    • 3
  2. Vid Luther
    2012-12-19T21:32:20+08:002012-12-19T21:32:20+08:00

    因此,对于 test.com,您正在访问具有 /www/app/www 文档根目录的第一个服务器块。

    对于 testapp.com,你正在点击 /www,然后希望 FPM 知道你想去 /www/www/app/www/index.php

    这是不会发生的。你能分享一下你的 fpm 配置的细节吗?特别是 chroot 和 chdir 部分?

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve