[nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理

[nginx]nginx的一个奇葩问题 500 Internal Server Error

解决方案

nginx 一直报500 Internal Server Error 错误,配置是通过phpstudy2018站点域名管理生成的。

默认是  root   "D:\php\phpstudy\PHPTutorial\WWW\foxphp";

修改成这样就好了

 root   "D:\\php\\phpstudy\\PHPTutorial\\WWW\\foxphp";

查找了很多资料,因为很奇葩,木有多少可供参考的,之前配置单斜杠一直木有问题,也找不到为毛产生的。有人说是地址问题,或许是单斜杠被当成转义符号了吧,那就再加一个,然后就没有然后了,php网站可以通过域名正常访问了。

好吧,nginx我确实没有系统的从头到尾学习,一般能有就好。个人愚见,遇见了奇葩问题就记录了下来进行分享,或许能够给别人带来帮助。

server {
        listen       80;
        server_name  k.cn ;
        root   "D:\\php\\phpstudy\PHPTutorial\\WWW\\kppw";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
server {
        listen       80;
        server_name  t.cn ;
        root   "D:\\php\\phpstudy\PHPTutorial\\WWW\\thinkphp\\public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
server {
        listen       80;
        server_name  o.cn ;
        root   "D:\\php\\phpstudy\PHPTutorial\\WWW\\opensns";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
server {
        listen       80;
        server_name  f.cn ;
        root   "D:\\php\\phpstudy\\PHPTutorial\\WWW\\foxphp";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
server {
        listen       80;
        server_name  abc.cn;
        root   "D:\\php\\phpstudy\\PHPTutorial\\WWW\\test";
        location / {
            index  index.html index.htm index.php;
            autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

 

linux-lnmp-nginx 配置

server
    {
        listen 80;
        #listen [::]:80;
        server_name l.cn *.l.cn;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/landv/php/fastadmin-weike/public;

        include rewrite/thinkphp.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        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/l.cn.log;
    }

 

出现当前权限不足,无法写入配置文件application/database.php解决方法

[nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理_第1张图片

/user/local/nginx/conf/fastcgi.conf简单粗暴修改这个文件

把fastcgi_param PHP_ADMIN_VALUE值修改即可

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/landv/php/fastadmin-weike/:/tmp/:/proc/";

 lnmp集成环境默认在最后一行。

因为lnmp默认会在虚拟主机目录创建一个.user.ini文件里面保存的是虚拟主机根目录配置信息

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

这个可以注释掉他。好吧坑那么多。

 

 还会出现其他文件权限问题,反正测试使用直接给到最大权限,正式使用的时候,只能给部分目录开放权限。

chmod -R 777 *

lnmp .user.ini文件无法删除解决方法

使用命令lnmp vhost del删除虚拟主机后,需要使用ftp或者rm命令删除网站目录,但是却发现网站目录下有个文件.user.ini文件没有自动删除,出现提示rm: cannot remove `’: Operation not permitted,连手动ftp也无法删除。

问题分析:根据上面的提示判断文件权限已经被锁定,需要先解除锁定。

问题解决:输入以下命令

chattr -i /home/wwwroot/你的网站目录/.user.ini

然后再用rm -rf命令或者FTP去删除就可以了。

 隐藏thinkphp的index.php url,可以不用改成和官方的一样

修改lnmp的pathinfo.conf文件

fastcgi_split_path_info ^(.+?\.php)(/.*)$;

修改成
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;

 thinkphp 隐藏index.php

server {
        listen       80;
        server_name  fast.cn ;
        root   "D:\\php\\phpstudy\\PHPTutorial\\WWW\\thinkphp\\fastadmin-weike\\public";
        location / {
            index  index.html index.htm index.php;
    if (!-e $request_filename) {
             rewrite  ^(.*)$  /index.php?s=/$1  last;
             break;
    }
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

真正起作用的是这一段配置:

if (!-e $request_filename) {
   rewrite  ^(.*)$  /index.php?s=/$1  last;
   break;
}

 

你可能感兴趣的:([nginx]nginx的一个奇葩问题 500 Internal Server Error phpstudy2018 nginx虚拟主机配置 fastadmin常见问题处理)