LNMP(lnmp.org) 环境下该网页无法正常运作 HTTP ERROR 500
renzhengzhang opened this issue · 9 comments
检查一下public目录下有没有.user.ini文件,如果没有改文件并且确定你的配置没问题的话,将该站点的目录文件以及文件夹的所有者改为www
附上 vhost 完整配置文件,域名已经用 domain.tld
替换
server
{
listen 80;
#listen [::]:80;
server_name domain.tld www.domain.tld;
return 301 https://domain.tld$request_uri;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name domain.tld www.domain.tld;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/domain.tld/public;
ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/domain.tld/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/domain.tld/domain.tld.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/none.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/domain.tld.log;
}
@zhangrenzheng 修改index.php,测试一下是否能正常访问站点,文件内容:
<?php phpinfo();
修改index.php
之后可以正常打开 php version 界面
@zhangrenzheng 开启lnmp的错误日志看一下
LNMP下的错误需要编辑 /usr/local/php/etc/php-fpm.conf 加上
php_admin_value[error_log] = /usr/local/php/var/log/php_errors.log
php_admin_flag[log_errors] = on
或在/usr/local/php/etc/php-fpm.conf里设置,加上catch_workers_output = yes,错误信息就会记录到php-fpm.conf里error_log设置的文件里。 上述两种方法都行,重启php-fpm生效 同理php.ini里的display_errors也是需要在php-fpm.conf里设置的,加上php_flag[display_errors] = On就开启了。 有时可能错误日志文件不自动创建,可以执行:touch /usr/local/php/var/log/php_errors.log && chown www:www /usr/local/php/var/log/php_errors.log
修改 usr/local/php/etc/php-fpm.conf
,恢复原来 index.php。打开网站显示如下:
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/domain.tld/thinkphp/base.php) is not within the allowed path(s): (/home/wwwroot/domain.tld/public/:/tmp/:/proc/) in /home/wwwroot/domain.tld/public/index.php on line 18
Warning: require(/home/wwwroot/domain.tld/thinkphp/base.php): failed to open stream: Operation not permitted in /home/wwwroot/domain.tld/public/index.php on line 18
Fatal error: require(): Failed opening required '/home/wwwroot/domain.tld/public/../thinkphp/base.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/domain.tld/public/index.php on line 18
在执行touch /usr/local/php/var/log/php_errors.log && chown www:www /usr/local/php/var/log/php_errors.log
之后,日志内容如下:
[root@***** public]# cat /usr/local/php/var/log/php_errors.log
[31-Mar-2019 21:40:48 PRC] PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/domain.tld/thinkphp/base.php) is not within the allowed path(s): (/home/wwwroot/domain.tld/public/:/tmp/:/proc/) in /home/wwwroot/domain.tld/public/index.php on line 18
[31-Mar-2019 21:40:48 PRC] PHP Warning: require(/home/wwwroot/domain.tld/thinkphp/base.php): failed to open stream: Operation not permitted in /home/wwwroot/domain.tld/public/index.php on line 18
[31-Mar-2019 21:40:48 PRC] PHP Fatal error: require(): Failed opening required '/home/wwwroot/domain.tld/public/../thinkphp/base.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/domain.tld/public/index.php on line 18
[31-Mar-2019 21:40:48 PRC] PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/domain.tld/thinkphp/base.php) is not within the allowed path(s): (/home/wwwroot/domain.tld/public/:/tmp/:/proc/) in /home/wwwroot/domain.tld/public/index.php on line 18
[31-Mar-2019 21:40:48 PRC] PHP Warning: require(/home/wwwroot/domain.tld/thinkphp/base.php): failed to open stream: Operation not permitted in /home/wwwroot/domain.tld/public/index.php on line 18
[31-Mar-2019 21:40:48 PRC] PHP Fatal error: require(): Failed opening required '/home/wwwroot/domain.tld/public/../thinkphp/base.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/domain.tld/public/index.php on line 18
@zhangrenzheng 可以确定是防跨站设置(.user.ini)引起的,解决方法请参考:
https://lnmp.org/faq/lnmp-vhost-add-howto.html#user.ini
@wisp-x 谢谢已经解决。
总结一下解决方法。
- 去除 /home/wwwroot/domain.tld/.user.ini 不得任意更动权限
chattr -i /home/wwwroot/domain.tld/.user.ini
- 移动 .user.ini 至 public 目录,重新加上权限
cd /home/wwwroot/domain.tld
mv .user.ini public
cd public
chattr +i .user.ini
由于
LNMP 1.4或更高版本如果不想用防跨目录或者修改.user.ini的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/"; 在该行行前添加 # 或删除改行,需要重启nginx。
- 进入 /path/lnmp1.x/tools, 其中 path 为lnmp路径
cd /path/lnmp1.x/tools
./remove_open_basedir_restriction.sh