I am trying to set up an CodeIgniter project with NGINX. However, it is an already website which is online, say for example test.com. This means that the project also has $config['base_url'] = 'test.com'
. But when I want to setup an NGINX server block I have to define the server name that is the same as the domain in base_url
, according to this post. However, I want to have url test.dev for the development and test.com should just link to the online website. How do I achieve this?

- 93
- 12
3 Answers
Set your ENVIRONMENT variable. https://www.codeigniter.com/user_guide/general/environments.html For your production
define('ENVIRONMENT','production');
and for development
define('ENVIRONMENT','production');
and in your config file you can check like this or any variables
if(ENVIRONMENT == 'development'){
$config['base_url'] = 'test.dev';
}else{
$config['base_url'] = 'test.com';
}

- 1,286
- 1
- 12
- 26
-
I tried this, but currently my test.dev gives "Problem loading page". Also `access.log` and `error.log` show no requests. My `/etc/nginx/sites-available/test.dev` file is like the one shown in the link in the original post. I've also created the symbolic link to `sites-enabled`. What am I doing wrong? – Stan Derksen Mar 07 '17 at 12:43
-
Adding `127.0.0.1 test.com` to my `/etc/hosts` file results in de "Welcome to nginx!" website when I try to access test.com. In other words, it now redirects to the default page. – Stan Derksen Mar 07 '17 at 12:58
-
I think this could be your vhost setting issue. http://stackoverflow.com/questions/15489919/nginx-static-index-redirect – shafiq.rst Mar 07 '17 at 16:47
Create Environments. Handling Multiple Environments
In your index.php Find a line which says
//define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
Under that line place a check on dirname and paste this code
switch(dirname(__FILE__))
{
case 'Path\of\your\live\server\folder':
define('ENVIRONMENT','production');
break;
case 'path\of\your\local\folder':
define('ENVIRONMENT','development');
break;
}
Now you have a global variable ENVIRONMENT which has values production or development. You can place a switch on this variable and give values to base_url in config.php or choose active group in database.php for DB credentials .

- 1,469
- 1
- 20
- 39
-
Apparently I'm having a different issue with nginx before this. See @shafiq his answer for more details. – Stan Derksen Mar 07 '17 at 13:00
In CI, you can define a config.php
file for each environment you are using.
In your config
folder, create a development
folder in which you place a config.php
file with the base_url
you need. Then, in that environment, CI will use that new file instead of the main config.php
file.

- 500
- 6
- 19
-
Apparently I'm having a different issue with nginx before this. See @shafiq's answer for more details. – Stan Derksen Mar 07 '17 at 13:01