⑴ 如何让nginx支持Thinkphp框架
让nginx支持ThinkPHP框架的做法:
1、打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件
添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ .php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
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;
}
⑵ 如何让nginx支持ThinkPHP框架
让nginx支持pathinfo,支持thinkphp
我们打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文
我们注释掉配置文件中那些被我圈出来的语句(location ~ \.php$ {……}这一段里面的),我们将对这部分进行重写!
将重写后的代码添加进去。
添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
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;
}
...................................
注意事项
一定要注释到原来的location ~ \.php$ {……}这一段里面的代码
不要漏掉{}
转载
⑶ nginx下怎么支持THinkPHP
thinkphp中设置如下:
“URL_MODEL”=>2
然后访问路径中加“/”的路径都是404状态;
网上很多解决方法,但是都一个样,中国的复制能力太强了,现在发表web集结号解决方法:
主要对未找到的链接在做匹配,
nginx.conf的配置如下方法:
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)index.php(.*)$ $1/index.php?s=$2 last; //关键语句
break;
}
}
新加“rewrite ^/(.*)index.php(.*)$ $1/index.php?s=$2 last;” 然后 用thinkphp 通用的兼容的解析方法处理,问题得到解决~
另外可以再解析php的改成如下:
location ~ .php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/data0/wwwroot/$fastcgi_script_name;
include fastcgi_params;
}
⑷ nginx下怎么支持THinkPHP
ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以nginx默认情况下是不支持thinkphp的。不过我们可以通过修改nginx的配置文件来让其支持thinkphp。
让nginx支持pathinfo,支持thinkphp
1
我们打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件
如何让nginx支持ThinkPHP框架
2
我们注释掉配置文件中那些被我圈出来的语句(location ~ \.php$ {……}这一段里面的),我们将对这部分进行重写!
如何让nginx支持ThinkPHP框架
3
将重写后的代码添加进去。
如何让nginx支持ThinkPHP框架
4
添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
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;
}希望能帮到你,我还在后盾人线下面授培训上课学习呢现在没时间,有不会的可以问我,加油吧(。・ω・。)ノ♡
⑸ ThinkPHP在nginx下怎么设置
让nginx支持pathinfo,支持thinkphp
我们打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件,添加的代码如下:
.........................................
location/{
if(!-e$request_filename){
rewrite^/(.*)$/index.php/$1last;
break;
}
}
location~.php{
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefcgi.conf;
set$real_script_name$fastcgi_script_name;
if($fastcgi_script_name~"^(.+?.php)(/.+)$"){
set$real_script_name$1;
set$path_info$2;
}
fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;
fastcgi_paramSCRIPT_NAME$real_script_name;
fastcgi_paramPATH_INFO$path_info;
}
...................................
⑹ ThinkPHP在nginx下怎么设置
主要对未找到的链接在做匹配,
nginx.conf的配置如下方法:
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)index.php(.*)$ $1/index.php?s=$2 last; //关键语句
break;
}
}
新加“rewrite ^/(.*)index.php(.*)$ $1/index.php?s=$2 last;” 然后 用thinkphp 通用的兼容的解析方法处理,问题得到解决~
另外可以再解析php的改成如下:
location ~ .php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/data0/wwwroot/$fastcgi_script_name;
include fastcgi_params;
}如果你对php有兴趣的话,可以向我一样在后盾人平台多看看自己学习学习,时间长了自己就慢慢明白了,希望能帮到你,给个采纳吧谢谢
ヽ(*´з`*)ノ
⑺ ThinkPHP在nginx下怎么设置
问题出在一个网站是基于ThinkPHP框架开发的,用默认的方法配置不行。通用解决方法的配置如下:server{if(!-e$request_filename){rewrite^/(.*)$/index.php/$1last;break;}}location~.+\.php($|/){.set$script$uri;set$path_info"/";if($uri~"^(.+\.php)(/.*)"){set$script$1;set$path_info$2;}fastcgi_paramPATH_INFO$path_info;fastcgi_paramSCRIPT_FILENAME/path/to/web-root$script;}原来fastcgi模块自带了一个指令专门用来解决此类问题的,该指令fastcgi_split_path_info,该指令会根据给定的正则表达式来分隔URL,从而提取出脚本名和pathinfo信息,使用这个指令可以避免使用if语句,配置更简单。(server部分的if语句可以用try_files来代替),新的配置如下:server{try_files$uri/index.php$uri;}location~.+\.php($|/){.fastcgi_split_path_info^(.+\.php)(/.*)$;fastcgi_paramPATH_INFO$fastcgi_path_info;fastcgi_paramSCRIPT_FILENAME/path/to/web-root$fastcgi_script_name;}参考:
⑻ 如何让nginx支持ThinkPHP框架
1、打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件
2、注释掉配置文件中那些被我圈出来的语句(location ~ \.php$ {……}这一段里面的),将对这部分进行重写!
3、将重写后的代码添加进去。添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
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;
}
⑼ 如何让nginx支持ThinkPHP框架
Thinkphp开发手册里面是有介绍的,修改nginx.conf
location/{//…..省略部分代码
if(!-e$request_filename){
rewrite^(.*)$/index.php?s=$1last;
break;
}
}
给你一个补全的:
server{
...
location/{
indexindex.htmindex.htmlindex.php;
#访问路径的文件不存在则重写URL转交给ThinkPHP处理
if(!-e$request_filename){
rewrite^/(.*)$/index.php/$1last;
break;
}
}
location~.php/?.*${
root/var/www/html/website;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
#加载Nginx默认"服务器环境变量"配置
includefastcgi.conf;
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
set$fastcgi_script_name2$fastcgi_script_name;
if($fastcgi_script_name~"^(.+.php)(/.+)$"){
set$fastcgi_script_name2$1;
set$path_info$2;
}
fastcgi_paramPATH_INFO$path_info;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name2;
fastcgi_paramSCRIPT_NAME$fastcgi_script_name2;
}
}
⑽ 如何让nginx支持ThinkPHP框架
ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以nginx默认情况下是不支持thinkphp的。不过我们可以通过修改nginx的配置文件来让其支持thinkphp。
END
让nginx支持pathinfo,支持thinkphp
我们打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件
我们注释掉配置文件中那些被我圈出来的语句(location ~ \.php$ {……}这一段里面的),我们将对这部分进行重写!
将重写后的代码添加进去。
添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
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;
}
...................................
一定要注释到原来的location ~ \.php$ {……}这一段里面的代码
不要漏掉{}