thinkphp nginx configures rewrite, and the address will have an extra .php
为情所困
为情所困 2017-06-16 09:18:37
0
2
867

thinkphp nginx configuration rewrite, the address will be an additional .php
,http://localhost:7080/.php?m=...
nginx configuration file
server
{

    listen 80;
    #listen [::]:80;
    server_name localhost 192.168.150.79 doc.mall.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /data/www/wwwroot/mall_doc;

include none.conf;

    #error_page   404   /404.html;
    location / {
            if (!-e $request_filename)
    {
            rewrite ^/index.php(.*)$ /index.php?s= last;
            rewrite ^(.*)$ /index.php?s= last;
            rewrite ^/(.*)$ /index.php/;
    }
    }

location ~ .php {

            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            set $path_info "";
            set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                    set $real_script_name ;
                    set $path_info ;
            }
            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO $path_info;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
            expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
            expires      12h;
    }

access_log  /data/www/wwwlogs/doc.mall.access_log;

}

rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
rewrite ^/ (.*)$ /index.php/$1;
I have tried these three methods
'URL_MODEL' => 2,
The php version is PHP 7.1.5

nginx version is: nginx/1.12.0

Has anyone encountered this situation?
php version can be accessed normally on 5.6.9

为情所困
为情所困

reply all(2)
某草草

This problem also occurred when I configured THINKCMF before

    if(!defined('_PHP_FILE_')) {
        if(IS_CGI) {
            //CGI/FASTCGI模式下
            $_temp  = explode('.php',$_SERVER['PHP_SELF']);
            define('_PHP_FILE_',    rtrim(str_replace($_SERVER['HTTP_HOST'],'',$_temp[0].'.php'),'/'));
        }else {
            define('_PHP_FILE_',    rtrim($_SERVER['SCRIPT_NAME'],'/'));
        }
    }

Later I found out that the problem is this $_SERVER['SCRIPT_NAME'] path problem in the constant. There are 2 solutions to it
1. You modify the data in the constant
2. Use APACHE
I can think of these two methods now
In addition, you can Follow my blog PHP programmer study notes

巴扎黑
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    
    
    location ~ \.php {
        
         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;
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template