2016-05-12 63 views
0

我在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/中。CodeIgniter在Nginx上调用/index.php而不是/basefolder/index.php?

我怀疑这是由于我的Nginx安装配置错误,而不是与CodeIgniter相关的东西?我的Nginx安装在Ubuntu 16.04上运行。/etc/nginx/sites-enabled/default的内容为:

location/{ 
    try_files $uri $uri/ /index.php; 
} 

location ~ \.php$ { 
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
    include fastcgi.conf; 
} 

是否还有其他我应该更改的内容?

+0

你需要'/ index.php'还是只需要改变'try_files'的默认值?有关更多信息,请参见[本文档](http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)。 –

+0

我会尝试没有。我正在以其他一些例子为基础。 –

回答

0

如果您的服务器具有在/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; 
} 

这样一来,任何URI,这并不是一个资源文件或比赛一个.php文件,将被路由到您的应用程序默认入口点/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才会被路由到该应用程序的默认入口点。

相关问题