MAMP(MAC php集成环境)thinkphp5 nginx 配置(fastadmin配置)

thinkphp5的 nginx 配置,官方文档参考: http://static.kancloud.cn/manual/thinkphp5/177576

 

fastadmin的 nginx 配置,官方文档参考:https://doc.fastadmin.net/doc/faq.html

server {
        listen       80;
        server_name  www.fa.com *.fa.com;
        root   "C:/phpstudy/WWW/fastadmin/public";
        location / {
            index  index.html index.htm index.php;
            #主要是这一段一定要确保存在
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
            #结束
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

 

使用MAMP PRO配置的时候, 可以将location /规则添加到nginx的第一个文本框。

#主要是这一段一定要确保存在
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }

第二段location是匹配的伪静态规则,需要修改对应的nginx配置。

如果直接添加到nginx配置界面的server部分,则会被追加到末尾,这就造成该规则不起作用

这里的server 额外添加的规则应该是解析静态资源目录的规则,如下:

location @rewrite {
        set $static 0;
        if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map|mp3|wav|m4a)$) {
            set $static 1;
        }
        if ($static = 0) {
            rewrite ^/(.*)$ /index.php?s=/$1;
        }
    }

 

 

下面才是真正修改伪静态规则的方法:

打开MAMP PRO ,菜单栏的 File -> Edit Template -> nginx, 修改大约196行开始,注释掉原来的 php解析规则,更改为:

location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

 

保存,并重启nginx即可生效。

 

 

posted @ 2020-07-30 10:46  前端小小菜  阅读(2388)  评论(0编辑  收藏  举报