(1)加载 htaccess 文件
# /etc/nginx/sites-available/dev.gingili.link (部分文件)
server {
listen 80;
root /home/wwwroot/dev.gingili.link; #网站所在目录的绝对路径
index index.php index.html index.htm; #目录索引
server_name 'dev.gingili.link'; #网站的域名
include /home/wwwroot/dev.gingili.link/.htaccess;
location / {
index index.html index.htm index.php; #目录索引
}
重点是:
include /home/wwwroot/dev.gingili.link/.htaccess;
让nginx 读取到 htaccess 文件
(2)开启 PATH_INFO 支持
location ~ \.php { # 不能有 $
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; # 添加这行
fastcgi_param PATH_INFO $fastcgi_path_info; #添加这行
fastcgi_param SCRIPT_FILENAME /home/wwwroot/www.gingili.link/$fastcgi_script_name;
include fastcgi_params;
}
在 index.php中写入
var_dump($_SERVER['PATH_INFO']);exit;
测试。
(3) 修改ci框架的配置文件
#application/config/config.php
$config['enable_query_strings'] = TRUE; // 开启支持
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'
(4)以 dev.gingili.link/login.html 为例写路由
#.htaccess
# login
rewrite ^(.*)/login.html$ /index.php?c=Login&m=Index;
测试:
#application/controllers/Login.php
class Login extends MY_Controller
{
public function __controller()
{
parent::__construct();
}
public function Index()
{
echo 'hello world';
exit;
}
}
输出: hello world;
中途遇到问题
测试nginx文件。报错
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
根据错误意思。换用户执行nginx
>su root
错误解决