我在Nginx服务器中运行CodeIgniter 3.0.6,子路径最终服务于/index.php
,而不是/<installdir>/index.php
。因此,如果我请求/CodeIgniter-3.0.6/home/
,我会得到/index.php
页面,而不是预期的/CodeIgniter-3.0.6/index.php
。请注意,我的CodeIgniter应用程序最终将驻留在/2016/
中。
我怀疑这是由于我的Nginx安装配置错误,而不是与CodeIgniter相关的原因?我的Nginx安装是在Ubuntu 16.04上运行的。/etc/nginx/启用/默认站点的内容为:
location / {
try_files $uri $uri/ /index.php;
}
location ~ '.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi.conf;
}
还有什么我应该换的吗?
如果您的服务器有一个主入口点为/CodeIgniter-3.0.6/index.php
的应用程序,您可能应该这样设置您的位置:
location / {
try_files $uri $uri/ /CodeIgniter-3.0.6/index.php;
}
location ~ '.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi.conf;
}
这样,任何与资源文件或.php
文件不匹配的URI都将被路由到应用程序的默认入口点/CodeIgniter-3.0.6/index.php
。
但是,如果有多个应用程序,例如/index.php
和/CodeIgniter-3.0.6/index.php
是两个不同的入口点,则可能需要为每个应用程序设置位置,可能如下所示:
location / {
try_files $uri $uri/ /index.php;
}
location /CodeIgniter-3.0.6 {
try_files $uri $uri/ /CodeIgniter-3.0.6/index.php;
}
location ~ '.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi.conf;
}
这样,只有以/CodeIgniter-3.0.6
开头的URI才会被路由到该应用程序的默认入口点。