Nginx configuration for CodeIgniter
Nginx server configuration for CodeIgniter
Nginx server configuration for CodeIgniter
My Environment
- System: CentOS 7
- Web Server: Nginx v1.17.2
- Application Server: php-fpm (based on PHP 7.2)
- Web Framework: CodeIgniter v3.1.10
Deploy CodeIgniter project
First, Goto Official website and download CodeIgniter.
Then, create a folder named ci in the root directory of the nginx server and extract the CodeIgniter framework code into this directory. As follow:
| 1 | [root@xyz html]# pwd | 
The path /usr/share/nginx/html is the default static files path of nginx in my machine. You can use any other path actually. Just for simple, my goal to test the nginx server configuration.
Edit Nginx server configuration
Edit nginx default configuration file named default.conf, which is in /etc/nginx/conf.d.
I highly recommend you back up before changing the server configuration.
| 1 | server { | 
Test
My codeigniter folder is ci which is located in /usr/share/nginx/html/ci.
- default controller - http://yourdomain/ci/index.php/- http://yourdomain/ci/index.php/welcome- The effect of these two urls is the same. They all execute the - indexfunction of- Welcomecontroller in- Welcome.phpfile.
- custom controller - Create a file named - Test.phpin- application/controllersdirectory and edit it as follow:- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 class Test extends CI_Controller {
 public function index() {
 echo "Test Controller index!";
 }
 public function hello() {
 echo "Hello CodeIgniter!";
 }
 }- Restart service and test: - http://yourdomain/ci/index.php/Test/- http://yourdomain/ci/index.php/Test/hello- All these work well.