1. 卓越技术网首页
  2. 运维技术
  3. Linux

nginx访问php页面access denied(403)如何解决

方法①

通过php-fpm日志,发现是php.ini中需要增加路径open_basedir路径设置:

原来的open_basedir = .:/tmp/

修改为:open_basedir = .:/tmp/:/var/www/html

其中/var/www/html就是nginx设置的root目录.
systemctl restart php-fpm.service 重启服务

再重新浏览phpinfo.php,一切ok!

方法②

vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
service php-fpm restart
chown nginx.nginx /usr/share/nginx/html/ -R #设置目录所有者
chmod 700 /usr/share/nginx/html/ -R #设置目录权限

方法③

打开/usr/local/php/etc/php.ini 或 /etc/php.ini 文件,找到cgi.fix_pathinfo

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0

配置修改为 cgi.fix_pathinfo=1,重启 php-fpm 和 nginx 后解决。

原创文章,作者:moon,如若转载,请注明出处:https://www.zyfun.cn/yunwei/157.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注