900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > nginx无法访问index.html ThinkPHP5 + nginx配置(index.php无法访问404)

nginx无法访问index.html ThinkPHP5 + nginx配置(index.php无法访问404)

时间:2018-08-19 06:05:35

相关推荐

nginx无法访问index.html ThinkPHP5 + nginx配置(index.php无法访问404)

下载ThinkPHP5后,在nginx下默认无法访问index.php,

假如文件系统路径是/home/www/

创建项目php5后欢迎页访问路径是:

http://xxxxx/home/www/php5/public/

上面链接可以访问,但是index.php以及包含参数的请求均会访问失败,返回404错误.

配置php.ini

vim /usr/local/php/lib/php.ini (根据你的安装路径xxx/php/lib/php.ini )

php.ini中的配置参数cgi.fix_pathinfo = 1

位置

接下来进入nginx的配置:

1 找到server里的location ~ .php$ { ...}

server {

.

location ~ \.php$ { ...}

.

}

修改为:

set $root /home/www/php5/public;

location ~ \.php($|/) {

root $root;

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;

}

修改解释:

1: 声明变量$root, 设置根目录:/home/www/php5/public (直接指向public)

2: 修改方法

修改前:

location ~ \.php$ : 只允许.php结尾的请求.所以带参数会失败

修改后:

location ~ \.php($|/) : 允许.php及带参数的请求

隐藏index.php:

也是找到server里的location / { { ...}

修改前:

location / {

root $root;

index index.html index.php index.htm;

}

修改后:(添加try_files

uri/ /index.php?$query_string; )

location / {

root $root;

index index.html index.php index.htm;

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=/$1 last;

break;

}

}

配置后出现访问资源文件报错模块不存在错误,这里只需添加对静态资源文件的特殊处理即可:

location ~ .*\.(css|js|gif|jpg|jpeg|png|bmp|swf)$ {

root $root;

expires 30d;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。