aleafo

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即可生效。

 

 

分类:

技术点:

相关文章:

  • 2021-10-20
  • 2021-11-26
  • 2021-04-21
  • 2021-08-02
  • 2021-09-29
  • 2021-08-11
  • 2021-09-15
  • 2021-09-29
猜你喜欢
  • 2021-10-08
  • 2021-08-09
  • 2022-03-07
  • 2022-02-12
  • 2022-01-23
  • 2021-12-28
  • 2021-07-07
相关资源
相似解决方案