首頁 > 後端開發 > php教程 > Nginx配置CodeIgniter計畫(二)

Nginx配置CodeIgniter計畫(二)

黄舟
發布: 2023-03-03 17:04:02
原創
1327 人瀏覽過

URL rewrite 方法

server { listen 8080; server_name www.xxx.com; root /Users/lch/work/www/ci; access_log /usr/local/var/log/access.log; error_log /usr/lousr/local/var/log/access.log; var/log/error.log; location ~ ^/(img|images|script|js|css|upload)/ { root /Users/lch/work/www/ci; break; } location ~ { if (!-e $request_filename) { # for /admin rewrite ^/(admin)$ /index.php?c=welcome&m=index&d=$1 break; # for /admin/index rewrite ^/(admin)/([a-zA-Z_] +)$ /index.php?c=$2&m=index&d=$1 break; # for /admin/account/login rewrite ^/(admin+)/([a-zA-Z_]+)/([a-zA- Z_]+)$ /index.php?c=$2&m=$3&d=$1 break; ## for general URL rewrite ^/([a-zA-Z_]+)/([a-zA-Z_]+) /?(.*)$ /index.php?c=$1&m=$2 last; } root /Users/lch/work/www/ci; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FENAME $doc fastcgi_script_name; include fastcgi_params; } }

說明一下上面的配置,因為我在application/controllers/裡面新建一個資料夾admin專門存放後台相關的controller,所以比普通的路徑&d =admin)這個參數。這裡可以看到rewrite方法的不足了,當有類似admin這種情況發生的時候就要加入對應的rewrite規則了。

PATH_INFO 方法

server { listen 8080; server_name www.xxx.com; root /Users/lch/work/kidulty/snap_www; access_log /usr/local/var/log/snap var/log/snap_error.log; location ~ ^/(img|images|script|js|css|upload)/ { root /Users/lch/work/kidulty/snap_www; break; } if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; } location ~ { set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?.php)(/.+ )$") { set $real_script_name $1; set $path_info $2; } root /Users/lch/work/kidulty/snap_www; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastc $ real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; } }

說明:

如果專案裡面URL類似http://www.xxx.com/index.php/user/proprofile

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

 以上是Nginx配置CodeIgniter專案(二)的內容,更多相關內容請關注PHP中文網(www .php.cn)! 


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板