今天在用tp5做项目的时候发现,前台是可以绑定默认到index模块的,但是后台不好弄,于是查了一下手册,按照手册上说的,复制了index.php改为admin.php,作为后台的入口文件,于是域名/admin.php就可以访问后台了(默认是admin模块的index控制器的index方法),虽然可以访问了,但是我是个完美主义者,或者说室友强迫症的人,我觉得admin.php的.php看上去很是刺眼,要是能去掉就更好了,于是我就想到了把nginx的配置改一下,抱着试一试的态度,结果还是挺满意的,去掉了尾巴看上去爽多了,下面贴上代码
入口文件admin.php
1 <?php 2 // +---------------------------------------------------------------------- 3 // | ThinkPHP [ WE CAN DO IT JUST THINK ] 4 // +---------------------------------------------------------------------- 5 // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. 6 // +---------------------------------------------------------------------- 7 // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) 8 // +---------------------------------------------------------------------- 9 // | Author: liu21st <liu21st@gmail.com> 10 // +---------------------------------------------------------------------- 11 12 // [ 应用入口文件 ] 13 14 // 定义应用目录 15 define('APP_PATH', __DIR__ . '/../application/'); 16 // 绑定到admin模块 17 define('BIND_MODULE','admin'); 18 // 加载框架引导文件 19 require __DIR__ . '/../thinkphp/start.php'; 20 21 ?>
后台首页Index.php
1 <?php 2 /* 3 *功能:后台首页控制器 4 *作者:魏安来 5 *日期:2017/12/12 6 */ 7 8 namespace appadmincontroller; 9 10 class Index extends Base{ 11 12 /*后台首页*/ 13 public function index(){ 14 return 'admin'; 15 //return $this->fetch(); 16 } 17 18 } 19 20 ?>
nginx配置vhosts.conf
1 server { 2 listen 80; 3 server_name www.tpmall.com tpmall.com; 4 root "F:/phpStudy/WWW/tpmall/public"; 5 location / { 6 index index.html index.htm index.php admin.php; 7 #autoindex on; 8 9 if (!-e $request_filename){ 10 rewrite ^(.*)$ /index.php?s=/$1 last; 11 } 12 if (!-e $request_filename){ 13 rewrite ^(.*)$ /admin.php?s=/$1 last; 14 } 15 16 } 17 location ~ .php(.*)$ { 18 fastcgi_pass 127.0.0.1:9000; 19 fastcgi_index index.php; 20 fastcgi_split_path_info ^((?U).+.php)(/?.+)$; 21 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 22 fastcgi_param PATH_INFO $fastcgi_path_info; 23 fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 24 include fastcgi_params; 25 } 26 }