首頁  >  文章  >  後端開發  >  Nginx配置CodeIgniter計畫(二)

Nginx配置CodeIgniter計畫(二)

黄舟
黄舟原創
2016-12-20 13:14:421292瀏覽

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)! 


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn