首页 > 后端开发 > 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/local/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_FILENAME $document_root$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_access.log; error_log /usr/local/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; fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; } }

说明:

如果项目里面URL类似http://www.xxx.com/index.php/user/profile这种就不用下面的rewrite:

if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; }
 以上就是Nginx配置CodeIgniter项目(二)的内容,更多相关内容请关注PHP中文网(www.php.cn)! 


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板