logo小熊博客
首页 代码速查表 fk标记语言示例 登录
目录
Nginx配置

安装Nginx

sudo apt update //更新软件包列表
sudo apt install nginx  //开始安装
sudo systemctl start nginx  //启动Nginx服务
sudo nginx -t       //检查nginx的代码错误
sudo systemctl status nginx.service  //检查Nginx服务的状态
sudo systemctl restart nginx  //重启Nginx服务

sudo tail -f /var/log/nginx/error.log  //检查 Nginx 错误日志

配置Nginx

Nginx的主配置文件通常位于/etc/nginx/nginx.conf,但你也可以在/etc/nginx/conf.d/目录下创建额外的配置文件来管理不同的网站或应用

server {  
            listen 80;  
            server_name 123.123.123; 
            root /var/www/yiheihie; 
            index index.html index.htm index.php;  

    # PHP处理配置
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location / {  
                try_files $uri $uri/ =404;  
        }  
}

安装php7.4

sudo add-apt-repository ppa:ondrej/php  //添加 PHP PPA
sudo apt install php7.4 php7.4-cli php7.4-fpm php7.4-mysql php7.4-pgsql php7.4-sqlite3 php7.4-mbstring php7.4-xml php7.4-curl php7.4-zip  //安装 PHP 7.4 和常见的 PHP 扩展
sudo systemctl restart php7.4-fpm  //重新启动服务

配置php文件

查看 PHP-FPM 的配置文件,配置文件位于 /etc/php/7.4/fpm/pool.d/www.conf

php_admin_value[open_basedir] = /var/www/boke:/tmp:/usr/share/php  //查找 listen 配置项,确认套接字路径

sudo systemctl restart nginx  //重新启动 Nginx 和 PHP-FPM 服务
sudo systemctl restart php7.4-fpm  


sudo tail -f /var/log/php7.4-fpm.log   //检查 PHP-FPM 错误日志

1.No input file specified

"No input file specified" 错误通常是由于 Nginx 和 PHP-FPM 的配置问题引起的。这个错误通常表明 PHP-FPM 无法找到要执行的 PHP 文件。以下是一些解决步骤和检查点:

1. 检查 PHP-FPM 套接字或端口配置

确保 fastcgi_pass 指定的路径是正确的,并且 PHP-FPM 正在使用该路径。默认情况下,PHP-FPM 使用 Unix 套接字进行通信,但也可以配置为使用 TCP 套接字。

  • 检查 PHP-FPM 套接字路径

查看 PHP-FPM 的配置文件,确保套接字路径正确。通常,配置文件位于 /etc/php/7.4/fpm/pool.d/www.conf

查找 listen 配置项,确认套接字路径:

listen = /var/run/php/php7.4-fpm.sock
  • 如果使用 TCP 套接字

如果 PHP-FPM 配置为使用 TCP 套接字,listen 行可能类似于:

listen = 127.0.0.1:9000

在这种情况下,fastcgi_pass 应该改为:

fastcgi_pass 127.0.0.1:9000;

2. 检查 Nginx 配置文件

确保 Nginx 配置中处理 PHP 文件的部分正确设置。以下是配置的正确示例:

server {
    listen 80;
    server_name 47.97.1.176;
    root /var/www/boke;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    # PHP处理配置
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 或者 fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

3. 检查文件权限

确保 PHP 文件和目录具有正确的权限,并且 Nginx 用户(通常是 www-data)可以读取这些文件。

1. 检查文件权限

sudo chown -R www-data:www-data /var/www/boke
sudo find /var/www/boke -type d -exec chmod 755 {} \;
sudo find /var/www/boke -type f -exec chmod 644 {} \;

4. 重新启动服务

在更改配置或权限后,重新启动 Nginx 和 PHP-FPM 服务以应用更改。

sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm

5. 检查 Nginx 错误日志

如果问题仍然存在,查看 Nginx 错误日志获取更多信息,这可能会帮助你诊断问题:

sudo tail -f /var/log/nginx/error.log

6. 确保 PHP-FPM 正在运行

确保 PHP-FPM 服务正在运行并且没有错误:

sudo systemctl status php7.4-fpm

这些步骤应帮助你解决 “No input file specified” 错误。如果仍然遇到问题,可以进一步提供详细的错误日志信息以获得更具体的帮助。

open_basedir

99 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/var/www/boke/info.php) is not within the allowed path(s): (/www/wwwroot/xxcxx_lat/:/tmp/) in Unknown on line 0PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0Unable to open primary script: /var/www/boke/info.php (Operation not permitted)" while reading response header from upstream, client: 59.174.16.184, server: 47.97.1.176, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "47.97.1.176"

这个错误信息表明 open_basedir 限制导致了 PHP 无法访问指定的文件。open_basedir 是 PHP 的一个配置选项,用来限制 PHP 脚本可以访问的目录。

错误分析

1. open_basedir restriction in effect:

PHP 的 open_basedir 设置限制了 PHP 脚本只能访问指定目录下的文件。在你的情况下,open_basedir 限制了 PHP 只能访问 /www/wwwroot/xxcxx_lat//tmp/ 目录,而 /var/www/boke/ 不在这些目录内。

2. failed to open stream: Operation not permitted:

PHP 尝试打开文件 /var/www/boke/info.php 时遇到了权限问题,因为这个文件不在 open_basedir 允许的路径内。

解决方法

1. 调整 open_basedir 配置

要解决这个问题,你需要将 PHP-FPM 的 open_basedir 设置调整为包括你的项目目录 /var/www/boke/

  • 打开 PHP-FPM 的配置文件,通常是 /etc/php/7.4/fpm/pool.d/www.conf 或其他类似路径。
  • 找到类似下面的配置项,如果没有,添加它:
php_admin_value[open_basedir] = /var/www/boke:/tmp:/usr/share/php

这里 /var/www/boke 是你需要添加的路径,/tmp/usr/share/php 是常见的路径,确保它们也在你的 open_basedir 设置中。

  • 如果你使用的是全局 PHP 配置文件(例如 /etc/php/7.4/php.ini),也可以在里面设置:
open_basedir = /var/www/boke:/tmp:/usr/share/php
  • 记得在更改配置后重启 PHP-FPM 服务:
sudo systemctl restart php7.4-fpm

2. 确认 Nginx 配置

确保 Nginx 的 fastcgi_param SCRIPT_FILENAME 设置正确,它应该包括 $document_root$fastcgi_script_name,像这样:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

3. 检查 PHP 配置的其他地方

有时 open_basedir 可能在多个地方被设置,包括 .htaccess 文件或者其他 PHP 配置文件。如果你在多个地方发现了 open_basedir 设置,需要确保它们都包含你的项目目录。

4. 检查配置是否正确

确保你的 PHP 和 Nginx 配置文件没有语法错误。你可以使用 nginx -t 检查 Nginx 配置:

sudo nginx -t

php -i | grep open_basedir 检查 PHP 的配置:

php -i | grep open_basedir

通过这些步骤,你应该能够解决 open_basedir 限制的问题,并使 PHP 能够正确访问所需的文件。

no value

root@iZbp12n8ytpbd2y6nunfpoZ:/etc/nginx# php -i | grep open_basedir open_basedir => no value => no value

如果 php -i | grep open_basedir 输出的是 no value,这表明在你的 PHP 配置中,open_basedir 并未设置。这意味着 PHP 的 open_basedir 限制并不是由 PHP 配置文件引起的。这个限制可能是由 PHP-FPM 的池配置文件(例如 /etc/php/7.4/fpm/pool.d/www.conf)设置的,或者是通过 Nginx 配置中的 fastcgi_param 指令应用的。

以下是你可以检查和调整的几个方面:

1.检查 PHP-FPM 池配置

确保在 PHP-FPM 的池配置文件中,open_basedir 被正确设置或不存在限制。通常,这些设置位于 /etc/php/7.4/fpm/pool.d/www.conf 文件中:

php_admin_value[open_basedir] = /var/www/boke:/tmp:/usr/share/php

如果 php_admin_value[open_basedir] 被设置为某个值,确保它包括你的项目目录。如果没有设置这个值,open_basedir 的限制可能是默认设置。

2. 检查 Nginx 配置

检查 Nginx 的配置文件,确保 fastcgi_param SCRIPT_FILENAME 被正确设置。配置文件通常位于 /etc/nginx/sites-available//etc/nginx/conf.d/ 中。查找如下配置:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

确保 $document_root$fastcgi_script_name 的组合可以正确指向 PHP 脚本的位置。

3. 查看 PHP 错误日志

查看 PHP 和 PHP-FPM 的错误日志,以确认是否有其他配置问题。日志文件的位置通常在 /var/log/php//var/log/php-fpm/ 目录下。查看最近的日志条目可能会提供更多线索:

cat /var/log/php7.4-fpm.log
cat /var/log/nginx/error.log

4. 重新加载配置

在修改了任何配置文件后,确保重新加载 PHP-FPM 和 Nginx 服务:

sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx

5. 检查 PHP-FPM 环境变量

有时 PHP-FPM 的配置可能通过环境变量设置 open_basedir。可以检查 php-fpm 进程的环境变量,确保没有特殊的环境设置导致此问题。使用以下命令检查:

ps eww <php-fpm-pid>

<php-fpm-pid> 替换为 PHP-FPM 进程的实际 PID。

通过上述步骤,你可以排除 PHP-FPM 和 Nginx 配置中的 open_basedir 设置问题,确保 PHP 脚本能够正常访问所需的文件。

上一篇:链接远程数据库
下一篇:android设置横屏
请我喝奶茶!
赞赏码
手机扫码访问
手机访问