最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
thinkphp部署在nginx下 500错误或404错误解决办法
时间:2022-06-25 02:29:04 编辑:袖梨 来源:一聚教程网
nginx是一个高性能并发的服务器软件,配置方面要稍微比apache复杂一点点。
本地部署成功的一个thinkphp框架,部署到服务器的时候,刚开始因为权限问题抛出404错误,然后chown之后,抛出了500的错误,但是首页能够访问。
复查,应该是伪静态rewrite出现问题了,找了好多文献,解决方案如下:
应该将
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
更改为:
location ~ .php
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /mnt/khdb1/wwwroot$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include /alidata/server/nginx/conf/fastcgi_params;
}
解决方案的思路:是由于在配置站点的时候,conf文件应该将整个对服务器的请求更改路径,即从“ location ~ .php” 这个开始的大括号内的,默认的nginxlocation行头location ~ .*.(php|php5)?$也要改。包括第一行的location都要修改为最上面。就可以解决抛出的500服务器错误“thinkphp 500错误”
nginx下运行出错404错误-找不到文件解决办法
解决方法一:修改ThinkPHP设置,不使用PATH_INFO
解决方法二(推荐):修改nginx设置,支持PATH_INFO
修改nginx.conf和fastcgi-params
将
php geshi">
location ~ .php$ {
修改为
location ~ .php/?.*$ {
将
fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name;
修改为
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?.php)(/.+)$”) {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name2;
将
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
修改为
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
完整的nginx虚拟主机区块配置如下:
server {
listen 80;
server_name www.amiku.cn amiku.cn;
root /www_amiku_cn;
include /www_amiku_cn/.htaccess;
index index.html index.htm index.php;
location ~ .*.(php|php5)/?.*$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_split_path_info ^(.+.php)(.*)$;
#fastcgi_param PATH_INFO $fastcgi_path_info;
set $path_info “”;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?.php)(/.+)$”) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /www_amiku_cn$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fcgi.conf;
}
}
另外附贴修改过的.htaccess,以满足nginx的伪静态和apache服务器的规则不同。
#RewriteEngine on
#RewriteRule ^index.html$ index.php/Index/index
#RewriteRule ^([A-Z][a-z]+).html$ index.php/$1/index
#RewriteRule ^([A-Z][a-z]+)-([a-z]+).html$ index.php/$1/$2
#RewriteRule ^([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([0-9]+).html$ index.php/$1/$2/$3/$4
#RewriteRule ^([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([x00-xff]+)-([a-z]+)-([0-9]+)-([a-z]+)-([0-9]+).html$ index.php/$1/$2/$3/$4/$5/$6/$7/$8 rewrite ^(.*)/index.html$ $1/index.php/Index/index;
rewrite ^(.*)/([A-Z][a-z]+).html$ $1/index.php/$2/index;
rewrite ^(.*)/([A-Z][a-z]+)-([a-z]+).html$ $1/index.php/$2/$3;
rewrite ^(.*)/([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([0-9]+).html$ $1/index.php/$2/$3/$4/$5;
rewrite ^(.*)/([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([x00-xff]+)-([a-z]+)-([0-9]+)-([a-z]+)-([0
-9]+).html$ $1/index.php/$2/$3/$4/$5/$6/$7/$8/$9;
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22