nginx适配thinkphp3.2.3

环境

centos7.9

nginx1.23.2

thinkphp3.2.3

PHP7.4.30

配置

配置nginx

默认位置在/usr/local/nginx/conf/nginx.conf主要配置locationlocation ~ \.php$

server {
    listen       80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {
        root   /var/www/html;
        index index.php index.html index.htm;
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php?s=$1 last;
            break;
        }
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        #包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取
        include   fastcgi.conf;
        set $path_info "";
        set $fastcgi_script_name_new $fastcgi_script_name;
        #判断url是否是pathinfo形式的,如果是则把这个url分割成两部分,index.php入口文件之后的pathinfo部分存入$path_info变量中,剩下的部分和$document_root根目录定位index.php入口文件在文件系统中的绝对路径 .
        if ($fastcgi_script_name ~*   "^(.+\.php)(/.+)$"  ) {
            set $fastcgi_script_name_new $1;
            set $path_info $2;
        }
        #对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写,目的是指定入口文件在文件系统中的绝对路径给script_filename参数,让fastcgi知道index.php文件位置。
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name_new;
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name_new;
        #定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个入口文件index.php后的pathinfo信息
        fastcgi_param   PATH_INFO $path_info;
    }
}

配置文件参考原文链接:https://www.cnblogs.com/koreyoshi/articles/10259961.html 

配置thinkphp

就是项目里的config.php文件,目录根据自己的项目而定,一般在/var/www/html/项目/Common/Conf添加两行内容

/* URL配置 */
'URL_CASE_INSENSITIVE' => true, // 默认false 表示URL区分大小写 true则表示不区分大小写
'URL_MODEL' => 2, // URL模式

end。

posted @ 2022-11-09 16:04  xjournal  阅读(353)  评论(0编辑  收藏  举报