thinkphp6.0的nginx配置(伪静态)

推荐一款好用的开源框架

https://gitee.com/pear-admin/Pear-Admin-Think

我在安装thinkphp版本时出现了一些问题,如图

询问了下开发者,发现并不是代码的问题 是开源框架thinkphp6.0的问题 thinkphp6.0的路由必须要开启pathinfo,但是nginx(thinkphp官方问中说低版本nginx不开启,但没说哪个版本是低版本,我的1.16.1没有开启,所以如果小伙伴的nginx在这个及以下,就可以使用我下面的配置了) 中默认不开启,遂在此分享下我的nginx配置

分享下我的nginx配置

server {
    listen       80;
    server_name  think.sanlilin.cn;
    root   /var/www/html/Pear-Admin-Think/public;

    index index.html index.htm index.php;
    charset utf-8;


    # redirect server error pages to the static page /50x.html
    #
    error_page   404              /index.php;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location / {
        #访问路径的文件不存在则重写URL转交给ThinkPHP处理
        index index.php;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires 100d;
    }
    location ~ .*.(js|css)?$ {
        expires 30d;
    }
    location ~ .php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        /etc/nginx/fastcgi_params;
        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;
    }
}

原文地址:https://www.cnblogs.com/sanlilin/p/14239485.html