Nginx 搭配 Laravel PHP Framework 設定

回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Nginx 搭配 Laravel PHP Framework 設定

文章 yehlu »

http://blog.wu-boy.com/2013/09/setup-la ... ith-nginx/

筆記在 Nginx 設定 Laravel 專案,現在的 PHP Framework 都將 query string 整個導向首頁 index.php,就拿 CodeIgniter 來說,在 Apache 只要設定
1
2
3
4
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|$)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
在 Nginx 內只要透過 try_files 即可
1
2
3
location / {
try_files $uri $uri/ /index.php
}
正常來說 Laravel 直接用上面的設定即可,但是我發現在 $_GET 這全域變數會拿到空值,解法也很簡單,在 Nginx 將 query string 變數帶到 index.php 後面即可
1
2
3
location / {
try_files $uri $uri/ /index.php?$query_string;
}
回覆文章

回到「nginx」