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

Kiran ·
更新时间:2024-09-21
· 888 次阅读

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入口文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。

您可能感兴趣的文章:Nginx下ThinkPHP5的配置方法详解解决tp5在nginx下修改配置访问的问题



Nginx

需要 登录 后方可回复, 如果你还没有账号请 注册新账号