Table of Contents
1、给PHP传递了错误的路径
2、不正确的文件权限
Home php教程 php手册 如何解决nginx+php报错“No input file specified”

如何解决nginx+php报错“No input file specified”

Jun 06, 2016 pm 08:13 PM
file input how Report an error solve

2014/07/02 21:53:02 [error] 4952#0: *8 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstr eam, client: 180.180.180.180, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:

2014/07/02 21:53:02 [error] 4952#0: *8 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstr eam, client: 180.180.180.180, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "100.100.100.100"
Copy after login

nginx+PHP,访问PHP页面显示空白并提示“No input file specified”,nginx错误日志中显示"Primary script unknown" 。这实际上是PHP在display_errors设置为off时,PHP报出的错误。在PHP默认安装下,会将错误输出到stderr或stdout、然后被nginx捕获并记录在error.log中。其根本原因是PHP无法找到nginx告诉它的相应文件,有一些原因可以导致这个问题,如下。

1、给PHP传递了错误的路径

大多数原因是初学者参考网上google的文章来配置导致的。Nginx通过 SCRIPT_FILENAME 这个 fastcgi_param 的值来告诉PHP需要执行的文件。网上大多数的文章将这个参数的值设置为 $document_root$fastcgi_script_name ,有时这样配置还是为了解决"No input file specified" 问题的。但是这会导致路径被“写死”,突然有一天你发现问题出现了。

原因在于nginx有三级配置继承关系:三个层次的区块分别为http、server 和 location,是父子的关系。nginx配置里的命令向下继承,但不会向上继承或交叉。比如你在一个 location中定义了一些东西,是不会应用到其他location中的。

典型的一些初学者,在 location / 中定义 index 和 root ,因为网上的文章是这么教的。当再使用 $document_root 来定义SCRIPT_FILENAME 时,root 并没有真正被定义,因此 SCRIPT_FILENAME 的值仅仅变成了URI,导致PHP找不到该文件。

简单的解决办法是在 server 或 http 区块中定义 root 。

2、不正确的文件权限

当我告诉他你的权限设置不正确时,大多数人都不相信我。他们盯着脚本文件的权限设置,PHP用户有读取权限啊!?很遗憾,这表现出他对Unix用户权限缺乏理解。PHP的启动用户不仅需要脚本文件的读权限,还需要能进入到脚本文件所在的目录(及上层目录),这就需要PHP用户拥有这些目录的执行权限。举一个例子:

说你在 /var/www 目录下有一个 index.php 的脚本文件,需要PHP用户对 /var/www/index.php 有读权限,且需要对 /var 和 /var/www 目录有执行权限。

我就遇到过一次新装的Debian nginx+php环境,在将PHP用户加入到 $document_root 目录拥有者的用户组后,因为没有重启 php-fpm 而导致的权限没有生效问题,查了半天原因。

[...]

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to the problem that Win11 system cannot install Chinese language pack Solution to the problem that Win11 system cannot install Chinese language pack Mar 09, 2024 am 09:48 AM

Solution to the problem that Win11 system cannot install Chinese language pack With the launch of Windows 11 system, many users began to upgrade their operating system to experience new functions and interfaces. However, some users found that they were unable to install the Chinese language pack after upgrading, which troubled their experience. In this article, we will discuss the reasons why Win11 system cannot install the Chinese language pack and provide some solutions to help users solve this problem. Cause Analysis First, let us analyze the inability of Win11 system to

Five tips to teach you how to solve the problem of Black Shark phone not turning on! Five tips to teach you how to solve the problem of Black Shark phone not turning on! Mar 24, 2024 pm 12:27 PM

As smartphone technology continues to develop, mobile phones play an increasingly important role in our daily lives. As a flagship phone focusing on gaming performance, the Black Shark phone is highly favored by players. However, sometimes we also face the situation that the Black Shark phone cannot be turned on. At this time, we need to take some measures to solve this problem. Next, let us share five tips to teach you how to solve the problem of Black Shark phone not turning on: Step 1: Check the battery power. First, make sure your Black Shark phone has enough power. It may be because the phone battery is exhausted

How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? Mar 22, 2024 am 08:06 AM

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

The driver cannot be loaded on this device. How to solve it? (Personally tested and valid) The driver cannot be loaded on this device. How to solve it? (Personally tested and valid) Mar 14, 2024 pm 09:00 PM

Everyone knows that if the computer cannot load the driver, the device may not work properly or interact with the computer correctly. So how do we solve the problem when a prompt box pops up on the computer that the driver cannot be loaded on this device? The editor below will teach you two ways to easily solve the problem. Unable to load the driver on this device Solution 1. Search for "Kernel Isolation" in the Start menu. 2. Turn off Memory Integrity, and it will prompt "Memory Integrity has been turned off. Your device may be vulnerable." Click behind to ignore it, and it will not affect the use. 3. The problem can be solved after restarting the machine.

Share the method to solve the problem that PyCharm cannot be opened Share the method to solve the problem that PyCharm cannot be opened Feb 22, 2024 am 09:03 AM

Title: How to solve the problem that PyCharm cannot be opened. PyCharm is a powerful Python integrated development environment, but sometimes we may encounter the problem that PyCharm cannot be opened. In this article, we'll share some common workarounds and provide specific code examples. Hope this helps those who encounter this problem. Method 1: Clear the cache Sometimes PyCharm’s cache files may cause the program to fail to open normally. We can try clearing the cache to solve this problem. Tool

How to solve the problem of default gateway automatically disappearing How to solve the problem of default gateway automatically disappearing Feb 24, 2024 pm 04:18 PM

How to solve the problem that the default gateway disappears automatically. In modern society, the Internet has become an indispensable part of people's lives. Whether for work or entertainment, we all need stable network connections to complete various tasks. The default gateway is one of the key elements connecting the local network to the external Internet. However, sometimes we may encounter the problem that the default gateway disappears automatically, resulting in the inability to access the Internet. So, how should we solve this problem when the default gateway disappears? First, we should clarify the concept of default gateway. The default gateway is a network route

How to solve the problem that Huawei browser has stopped accessing this webpage How to solve the problem that Huawei browser has stopped accessing this webpage Feb 26, 2024 pm 01:28 PM

How to solve the problem that Huawei browser has stopped accessing this webpage? When using Huawei mobile browser to access certain websites, a prompt indicating that access is prohibited may appear, preventing users from browsing related content normally. This is very inconvenient for users. So, what should we do when we encounter a situation where access to the Huawei mobile browser website is prohibited? The editor below will provide you with solutions to the problem of prohibiting access to Huawei browser websites. I hope it will be helpful to you. Solution to the prohibition of access to the Huawei Browser website 1. After opening the Huawei mobile browser, click the three-dot icon below, and then click Settings. 2. After entering the settings, click [Security and Privacy] 3. Turn off the switch on the right side of [Safe Browsing] to remove website access restrictions. The above is the solution to the ban on Huawei browser website access.

Interpreting Oracle error 3114: causes and solutions Interpreting Oracle error 3114: causes and solutions Mar 08, 2024 pm 03:42 PM

Title: Analysis of Oracle Error 3114: Causes and Solutions When using Oracle database, you often encounter various error codes, among which error 3114 is a relatively common one. This error generally involves database link problems, which may cause exceptions when accessing the database. This article will interpret Oracle error 3114, discuss its causes, and give specific methods to solve the error and related code examples. 1. Definition of error 3114 Oracle error 3114 pass

See all articles