Nginx Configuration CI Framework problem (CentOS system under Linux platform)

Source: Internet
Author: User
Tags nginx server

CI Framework: Official document Http://codeigniter.org.cn/user_guide/index.html

The data flow diagram for the CI framework is as follows:

Where: index.php as a portal file, after the installation of the CI framework, the index.php file is generally placed in the Nginx server (other servers the same) configured Web root directory, nginx configuration file in xxx/nginx/conf/ The nginx.conf file, where xxx is the installation path, such as configuration. PHP parsing files can be used as the following template:

1 server {2Listen 80;//ports to listen on3root/dir_1/dir_2/dir_3;4server_name www.example.com;5Index index.html index.htm Index.php;6 7Location/8         {9Try_files$uri $uri//index.php?$args;Ten         } OneLocation ~ \.php$ A         { -Fastcgi_pass 127.0.0.1:9000; -Fastcgi_index index.php; the             includeFastCGI.conf; -         } -}

Where the index.php file is to be placed under the root directory/dir_1/dir_2/dir_3. The URL is www.example.com:port/index.php/class/function/arg or Www.example.com/class/function/arg, Where www.example.com can be replaced by IP address plus port number, nginx default listener port number is 80, so when the port is 80 can not add, other ports to be explicitly specified in the URL

————————————————————————————————————————————————————————

When there are multiple CI framework projects that need to be laid out on the Nginx server, there are two ways:

1. Configure a virtual machine in the Nginx configuration file and reset the root directory to listen for unused port numbers (not recommended)

2. You do not need to change the root directory, you need to use the rewrite directive and modify the routing rules in the CI framework, that is, the $route array, as follows:

For example, when the index file is located in/dir_1/dir_2/dir_3/test1/test2/test3/index.php

First: change the Nginx configuration file to:

Server {Listen80;//ports to listen onroot/dir_1/dir_2/dir_3; server_name www. Example.com; Index index. HTML index.htm Index.PHP; Location/{try_files$uri $uri//index.php?$args; } Location~ \.php$ {fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.PHP; includeFastCGI.conf; } Location/test1/test2/test3/{rewrite^/test1/test2/test3/(. *) $/test1/test2/test3/index.php/$1 Break; Fastcgi_index Index.PHP; Fastcgi_pass127.0.0.1:9000; includefastcgi.conf;//fastcgi.conf for PHP parsing library related text}}

where fastcgi.conf for their own definition, if not, can be replaced by:

1 $document _root$fastcgi_script_name ; 2 include Fastcgi_params;

PS: after each configuration of Nginx, remember to restart Nginx, so that the configuration takes effect!

then , modify the CI framework in the middle of the rules, in the CI application/conf directory, locate the routes.php file, add at the end:

$route [' test1/test2/test3/(. +) '] = "$";

The URL can then be www.example.com:port/test1/test2/test3/class/function/arg, View PHP Www.access.log can be found, Nginx has rewritten the link as Www.example.com:port/test1/test2/test3/index.php/class/function/arg, Similarly, because the Nginx default listener port number is 80, so when the port is 80 can not add, the other ports to be explicitly indicated in the URL.

Nginx Configuration CI framework problem (CentOS system under Linux platform)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.