lnmp1.3 配置pathinfo---thinkphp3.2 亲测有效

lnmp1.3环境下配置pathinfo模式试了很多方法,都以失败告终,博主被这个问题困扰了很久,终于解决了!现记录如下:

1、打开php.ini

 

通常该文件在 /usr/local/php/etc/php.ini 

vi /usr/local/php/etc/php.ini

找到 cgi.fix_pathinfo默认为0,修改为1,保存退出; 

2、打开nginx.conf配置文件

 

通常该文件在 /usr/local/nginx/conf/nginx.conf 

vi /usr/local/nginx/conf/nginx.conf 

(1)找到 include enable-php.conf;注释掉,在下面一行添加include enable-php-pathinfo.conf; 
 
(2)添加以下代码,并保存退出

复制代码
 1 #Rewrite模式
 2 location / { 
 3                 index  index.htm index.html index.php;
 4                 if (!-e $request_filename) {
 5                         rewrite  ^/(.*)$  /index.php/$1  last;
 6                         break; 
 7                 } 
 8         } 
 9  #pathinfo模式
10 location ~ \.php/?.*$ { 
11                 root        /home/wwwroot/default;
12                 fastcgi_pass   127.0.0.1:9000;
13                 fastcgi_index  index.php;
14                 include        fastcgi.conf;
15                 #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
16                 set $fastcgi_script_name2 $fastcgi_script_name;
17                 if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
18                         set $fastcgi_script_name2 $1;
19                         set $path_info $2;
20                 } 
21                 fastcgi_param   PATH_INFO $path_info;
22                 fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
23                 fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
24         } 
复制代码

 

 

(3)重启nginx 

service nginx restart 


这样就可以用pathinfo模式访问了 


提示:项目中必须设置’URL_MODEL’ => 1才能用pathinfo模式访问 
当设置’URL_MODEL’ => 2时,也可以用Rewrite模式访问

3、贴出完整server(截止此处已经成功,下面代码仅供参考)

server
    {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        server_name www.lnmp.org;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;
        #include enable-php.conf;
        include enable-php-pathinfo.conf;
        #Rewrite模式
        location / {
                index  index.htm index.html index.php;
                #访问路径的文件不存在则重写URL转交给ThinkPHP处理
                if (!-e $request_filename) {
                        rewrite  ^/(.*)$  /index.php/$1  last;
                        break;
                }
        }
        #pathinfo模式
        location ~ \.php/?.*$ {
                root        /home/wwwroot/default;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                #加载Nginx默认"服务器环境变量"配置
                include        fastcgi.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_param   PATH_INFO $path_info;
                fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
                fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
        }

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
    location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
        access_log  /home/wwwlogs/access.log;
    }

作者:itbaby

出处:https://www.cnblogs.com/itbaby/p/8025149.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   知风阁  阅读(352)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示