浅谈thinkphp的nginx配置,以及重写隐藏index.php入口文件方法

1,心血来潮,把ThinkPHP项目部署到了nginx上,以上是在apache上跑的。突然发现nginx不支持pathinfo功能,难怪在TP中调怎么都没管用。

2,开始上文件了,比网上其他一些杂的好多了:

server {

listen 80;

#listen [::]:80;

server_name www.tp.com tp.com;

index index.html index.htm index.php default.html default.htm default.php;

root /home/wwwroot/www.tp.com;

include index.php.conf;

#error_page 404 /404.html;

#include enable-php.conf;

include enable-php-pathinfo.conf; ##这个地方需要说明下:我用的是lnmp一键安装包,可能这个pathinfo.conf配置文件名有些不一样,

## 有文件名为enable-php.conf,也有enable-php-pathinfo.conf

## 目录在/usr/local/nginx/conf 可以自己去看看,带有pathinfo

#error_page 404 /404.html

location /app/ { #因为我的项目入口文件是放到app目录中的(app目录与Think目录同级),这样实现了隐藏index.php功能

if (!-e $request_filename) {

rewrite ^/app/(.*)$ /app/index.php/$1 last;

break;

}

}

location ~ ^(.+\.php)(.*) {

try_files $uri =404;

fastcgi_pass 127.0.0.1:9000;

fastcgi_pass unix:/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

# include fcgi.conf;

set $real_script_name $fastcgi_script_name;

set $path_info “”;

if ($fastcgi_script_name ~ “^(.+?.php)(/.+)$”){

set $real_script_name $1;

set $path_info $2;

}

fastcgi_param SCRIPT_FILENAME $document_root

$real_script_name;

fastcgi_param SCRIPT_NAME $real_script_name;

fastcgi_param PATH_INFO $path_info;

}

access_log /home/wwwlogs/www.tp.com.log;

}

直接上我的配置文件截图吧:

我的目录结构

看,现在可以支持以下路由了,pathinfo以及rewrite隐藏index.php入口文件

以上这篇浅谈thinkphp的nginx配置,以及重写隐藏index.php入口文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

以上是 浅谈thinkphp的nginx配置,以及重写隐藏index.php入口文件方法 的全部内容, 来源链接: utcz.com/p/223602.html

回到顶部