lsky-org/lsky-pro

LNMP(lnmp.org) 环境下该网页无法正常运作 HTTP ERROR 500

renzhengzhang opened this issue · 9 comments

环境

  • CentOS 7
  • LNMP(lnmp.org)
  • PHP 7.1.18
  • lsky-pro V1.5.2

具体情况

lnmp.conf
Snipaste_2019-03-31_11-19-09.png

在安装LNMP之后,添加 vhost。
修改网站根目录为 /home/wwwroot/domain.tld/public,添加伪静态。
Snipaste_2019-03-31_11-14-09.png

重启 nginx。
删除网站根目录目录下内 .user.ini。
Snipaste_2019-03-31_11-11-27.png

打开网站 500 错误。

检查一下public目录下有没有.user.ini文件,如果没有改文件并且确定你的配置没问题的话,将该站点的目录文件以及文件夹的所有者改为www

没有修改文件,一开始根据使用手册,删除了网站根目录的 .user.ini。

如果访问首页出现500,极大的可能性是因为lnmp开启了防跨站攻击,在站点根目录会生成一个.user.ini,删除该文件即可。

刚才在public文件夹下添加.user.ini,当然也修改了权限。重启 Nginx 之后还是 500 错误。
Snipaste_2019-03-31_20-45-49.png

另外在 oneinstack 的lnmp上安装成功。

附上 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

Snipaste_2019-03-31_21-43-32.png

在执行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 谢谢已经解决。

总结一下解决方法。

  1. 去除 /home/wwwroot/domain.tld/.user.ini 不得任意更动权限
chattr -i  /home/wwwroot/domain.tld/.user.ini
  1. 移动 .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。

  1. 进入 /path/lnmp1.x/tools, 其中 path 为lnmp路径
cd /path/lnmp1.x/tools
./remove_open_basedir_restriction.sh

输入目前网站根目录即可
Snipaste_2019-03-31_22-09-34.png