今天在用tp5做项目的时候发现,前台是可以绑定默认到index模块的,但是后台不好弄,于是查了一下手册,按照手册上说的,复制了index.php改为admin.php,作为后台的入口文件,于是域名/admin.php就可以访问后台了(默认是admin模块的index控制器的index方法),虽然可以访问了,但是我是个完美主义者,或者说室友强迫症的人,我觉得admin.php的.php看上去很是刺眼,要是能去掉就更好了,于是我就想到了把nginx的配置改一下,抱着试一试的态度,结果还是挺满意的,去掉了尾巴看上去爽多了,下面贴上代码
入口文件admin.php
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- // [ 应用入口文件 ] // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 绑定到admin模块 define('BIND_MODULE','admin'); // 加载框架引导文件 require __DIR__ . '/../thinkphp/start.php'; ?>
后台首页Index.php
<?php /* *功能:后台首页控制器 *作者:魏安来 *日期:2017/12/12 */ namespace app\admin\controller; class Index extends Base{ /*后台首页*/ public function index(){ return 'admin'; //return $this->fetch(); } } ?>
nginx配置vhosts.conf
server { listen 80; server_name www.tpmall.com tpmall.com; root "F:/phpStudy/WWW/tpmall/public"; location / { index index.html index.htm index.php admin.php; #autoindex on; if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=/$1 last; } if (!-e $request_filename){ rewrite ^(.*)$ /admin.php?s=/$1 last; } } 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; } }
到此这篇关于TP5多入口设置实例讲解的文章就介绍到这了,更多相关TP5多入口设置内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!