(1)加载 htaccess 文件php
# /etc/nginx/sites-available/dev.gingili.link (部分文件)html
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; #目录索引 }
重点是:nginx
include /home/wwwroot/dev.gingili.link/.htaccess;
让nginx 读取到 htaccess 文件shell
(2)开启 PATH_INFO 支持app
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.phpunix
$config['enable_query_strings'] = TRUE; // 开启支持 $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'
(4)以 dev.gingili.link/login.html 为例写路由code
#.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
错误解决