apache报错:Internal Server Error:The server encountered an internal error or misconfiguration and was

一、背景

      从新公司拉下代码之后,在本地迟迟跑不起来。本来以为是laravel+vue.js的原因,但是在我装好vue的所有依赖之后,还是无法访问项目。。

报错信息:

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

翻译:
服务器遇到内部错误或配置错误,无法完成您的请求。
请与服务器管理员[email protected]联系,并通知他们错误发生的时间,以及可能导致错误的任何事情。
关于这个错误的更多信息可以在服务器错误日志中找到。

二、解决Internal Server Error

      首先出现这个问题,我们看看翻译,应该是路径的问题。对于apache来说,要么是访问权限不对,要么就是重写模块没有打开。那么思路就很清晰了

1、访问权限开到最大

1、打开apache的配置文件
2、在apache配置文件httpd.conf中搜索 
AllowOverride None 
然后改为AllowOverride All 

2、打开重写模块

1、打开apache的配置文件
2、去掉LoadModule rewrite_module modules/mod_rewrite.so 的注释
3、重启apache

结果:一如既往的报错,,,emmmm

三、查看错误日志

既然根据前半段的翻译,咱们判断失误,那么就看后半段的翻译,,查看错误日志!

1、错误日志提示:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

翻译:
由于可能的配置错误,请求超过10次内部重定向的限制。如果必要的话,使用“限制内递”来增加限制。使用“LogLevel debug”获取回溯。

根据翻译,可以看到应该是路径重定向的问题,关于重定向的方面,我们一般都写在.htaccess文件中。

2、修改重写规则

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$  /index.php/$1 [PT,L] 

3、重启apache

      结果还是一如既往的报错??不过此时的报错信息已经发生改变,证明咱们的解决思路是没问题的。

四、apache报错:No input file specified.

1、没有输入文件指定,那么一定是咱们刚才重写规则部分的问题。修改重写规则为:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]

2、重启apache

      重启之后,发现可以正常访问项目了。我们重写规则的时候,只是多加了一个“?”,那么为什么一个问好就能有这么大的作用呢?接下来我们解析下这个正则:

3、解释

RewriteRule ^(.*)$ /index.php?/$1 [L]

1、这句正则的意思,前面的^(.*)$代表前面的路径是任意匹配的,一直到碰到index.php为止。

2、问好在正则中的意思:问号可以表示重复前面内容的0次或一次,也就是要么不出现,要么出现一次。也就是说,这个index.php可以有,也可以没有,并不是强制的

3、后面的$1代表正则中的第一个括号中的内容,也就是(.*)这部分

结论:所以,我们没加‘’?‘’之前,相当于在路径中,必须要含有这个index.php。而在我们加了‘’?‘’之后,相当于这个index.php有或者没有都可以,这样就加大的匹配的范围,因此可以正常访问到项目。

end

猜你喜欢

转载自blog.csdn.net/LJFPHP/article/details/80880958