版权声明:转载需附上本文地址 https://blog.csdn.net/weikaixxxxxx/article/details/86591765
没有对nginx进行配置,是访问不了tp的。
tp5所在目录
/usr/local/nginx/html/tp5
修改/usr/local/nginx/conf/nginx.conf
,在http段内的server段内添加,存在的覆盖
location / {
root /usr/local/nginx/html;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
}
}
location ~ \.php {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /
:匹配根目录
!-e $request_filename
:如果找不到请求的页面rewrite
:重定向-
^/(.*)$ /index.php/$1
:在域名后加入index.php,意思就是没有输入index.php会解析到有index.php的地址去
-
last
:停止处理当前的ngx_http_rewrite_module指令集,并开始搜索与更改的URI匹配的新位置
location ~ \.php {}
:匹配带.php的地址
root
:指定访问目录fastcgi_pass
:fastcgi地址fastcgi_index
:-
index.php
:默认首页文件
fastcgi_split_path_info
与fastcgi_param
:添加pathinfofastcgi_param
:-
$document_root$fastcgi_script_name
:读取$document_root(网站根目录)下的.php文件
include fastcgi_params
:引入fastcgi配置文件
重启nginx
访问浏览器
ip/tp5/public/
访问index模块index控制器下的hello方法
ip/tp5/public/index.php/index/index/hello
访问自带的路由
ip/tp5/public/index.php/hello/heiheihei