1. 程式人生 > >Laravel的Nginx重寫規則完整代碼

Laravel的Nginx重寫規則完整代碼

spa nginx錯誤 action cgi code file pre req permanent

laravel基本重寫規則

location / {
        index  index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$query_string ;  
}

去除末尾的斜杠,SEO更加友好

if (!-d $request_filename)
{
      rewrite ^/(.+)/$ /$1 permanent;
}

去除index action

if ($request_uri ~* index/?$)
{
         rewrite ^
/(.*)/index/?$ /$1 permanent; }

根據laravel規則進行url重寫

if (!-e $request_filename)
{
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
}

錯誤信息跳轉頁面必須在location ~ \.php(.*)${}裏面加入條:fastcgi_intercept_errors on開啟錯誤檢測信息
#nginx錯誤信息跳轉自定義頁面50x.html自己隨便定義

error_page  404 500 502 503 504 error.html;
location 
= error.html { root html; }

root是error文件的根目錄

Laravel的Nginx重寫規則完整代碼