以前我在我的CodeIgniter网站上使用运行Apache的linode VPS。 今天我安装了nginx,我的网站登陆页面即将到来,但其他使用htaccess重写URL的页面并没有到来。 这是我的htaccess,
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1
什么是我的htaccess nginx equalent? 在codeigniterconfiguration和应用程序中,我还需要做什么修改?
对于codeigniterconfiguration中的URI协议,我正在使用,
$config['uri_protocol'] = 'PATH_INFO';
这将与Nginx的工作?? ..
由于没有等效于.htaccess文件(即没有目录级configuration文件),您需要更新主configuration并重新加载nginx以使所有更改生效。
上面的Apacheconfiguration基本上读取“如果提供的path不是现有的文件或目录,redirect到index.php,追加path”。
在Nginx中,你将使用try_files指令来完成同样的事情:
location / { try_files $uri $uri/ @ci_index; } location @ci_index{ rewrite ^(.*) /index.php?$1 last; }
与Apache不同的是,在Nginxconfiguration中最好避免使用 if语句。
在一些设置中,您可以避免指定的索引并重写,只需使用/index.php作为try_files的第三条path(codeigniter应该从$_SERVER[$config['uri_protocol']]获取path。
至于PATH_INFO的使用 – 检查你的fastcgi_params文件(你希望包含在你的php位置块中),看看:
fastcgi_param PATH_INFO $fastcgi_path_info;
你也可以使用$config['uri_protocol'] = "REQUEST_URI"
对于您select的任何选项,请检查print_r($_SERVER)的输出以validation已设置哪些服务器variables以及它们已设置为什么(它们应该与您在PHP位置块和fastcgi_params文件中指定的内容相匹配) 。
我想这个链接将帮助你弄清楚添加到@ cyberx86的重点。 http://wiki.nginx.org/ModuleComparisonMatrix