laravel项目在lnmp环境上线出现404错误

项目上传到服务器后出现了404的错误,查看了错误日志:

PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0

  

Unable to open primary script: /www/wwwroot/yjx.ycqmd.top/public/index.php (Operation not permitted)" while reading response header from upstream, client: 118.78.36.242, server: yjx.ycqmd.top, request: "GET /home/index HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-71.sock:", host: "tk.ycqmd.top"

  

2020/02/29 18:06:16 [error] 24746#0: *1267 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/www/wwwroot/yjx.ycqmd.top/public/index.php) is not within the allowed path(s): (/www/wwwroot/xiaoying/:/tmp/:/proc/) in Unknown on line 0

  

查看问题描述以及资料,发现是open_basedir的问题,php不能引入其授权目录上级及其以上的文件。

关于open_basedir有三个方法可以修改:

1、默认配置在php.ini(/www/server/php/72/etc/php.ini)。

不过我的php.ini中是默认的配置:

;open_basedir =

可以在等号后添加网站的根目录路径,

2、在fastcgi.conf(/www/server/nginx/conf/fastcgi.conf)

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

或者把$document_root改为网站根目录路径

但是如果服务器有多个项目,这样改就不合适了,这时候可以用第三种方法

3、在.user.ini(根目录)
open_basedir=/www/wwwroot/yjx.ycqmd.top:/tmp/:/proc/

如果这几个文件都没有问题,可能是网站的访问入口地址不在根目录(我也是这种问题)

在laravel项目中,会把访问入口地址改为/public,所以.user.ini文件也要放到/public目录下。

原文地址:https://www.cnblogs.com/guanzelin/p/12384696.html