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;
    }
}


免責聲明!

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



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