我正在尝试 nginx 并将我现有的 apache 配置移植到 nginx。我已成功重新路由 codeigniter url,但我遇到了一个问题,即某个控制器的名称与站点根目录中的目录一致。
我设法使我的 codeigniter url 像在 Apache 中一样工作,只是我有一个特定的 url 说http://localhost/hello
与一个hello
站点根目录中的目录。Apache 对此没有问题。但 nginx 会路由到此目录而不是控制器。
我的重新路由结构如下
http://host_name/incoming_url => http://host_name/index.php/incoming_url
所有 codeigniter 文件都位于站点根目录。
我的 nginx 配置(相关部分)
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
index index.php index.html index.htm;
try_files $uri $uri/ /index.php/$request_uri;
#apache rewrite rule conversion
if (!-e $request_filename){
rewrite ^(.*)/?$ /index.php?/$1 last;
}
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php.*$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
编辑:
我的相关 apache htaccess 配置
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
我是 nginx 新手,我需要帮助找出与控制器名称冲突的目录。我从网络上的各种来源找到了此配置,如果有更好的配置编写方法,我将不胜感激。