nginx配置thinkphp5


1.根據官方文檔,下載tp5最新代碼

地址    https://www.kancloud.cn/manual/thinkphp5/118003

步驟:(使用git安裝)

①首先克隆下載應用項目倉庫

git clone https://github.com/top-think/think tp5

②然后切換到tp5目錄下面,再克隆核心框架倉庫:

git pull https://github.com/top-think/framework

③驗證是否安裝成功,在瀏覽器中輸入地址

http://localhost/tp5/public/

這時,瀏覽器中不知道你輸入的地址指向的是誰,在nginx服務器下配置相應的配置文件,給項目獨立的端口並指向相應地址,在conf.d文件中新建XXX.conf文件

server {
    listen       8801;
    server_name  localhost;
    root   D:/tp/myProject/tp5/public;
    index  index.php index.html index.htm;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;
    location / {
             if (!-e $request_filename){
                rewrite  ^/(.*)$  /index.php?s=/$1  last;
            }
        }

    location = /favicon.ico { access_log off; log_not_found off; }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   D:/tp/myProject/tp5/public;
    }

    #
    location ~ \.php$ {
        root           D:/tp/myProject/tp5/public;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny  all;
    }
}

在瀏覽者輸入localhost:8801,會成功出現成功內容

Nginx支持TP5pathinfo路由規則

 

1 location / {
2              if (!-e $request_filename){
3                 rewrite  ^/(.*)$  /index.php?s=/$1  last;
4             }
5         }

可以在瀏覽器中輸入http://localhost:8801/index/index/hello。使用pathinfo方式訪問控制器/類/方法

未配置pathinfo時,在瀏覽器中輸入?s=/index/index/hello 來訪問相應方法。


免責聲明!

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



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