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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM