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
index
function ofWelcome
controller inWelcome.php
file.custom controller
Create a file named
Test.php
inapplication/controllers
directory 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.
-
2020-04-13
-
2019-04-07
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
-
2019-06-17
CGI、FastCGI、WSGI、uwsgi、uWSGI 的联系与区别。
-
2019-04-12
介绍 Hexo 常用命令的作用。
-
2020-03-25