Home >Backend Development >PHP Tutorial >Configuring the codeigniter framework under Nginx

Configuring the codeigniter framework under Nginx

WBOY
WBOYOriginal
2016-08-08 09:26:46889browse

A WeChat official account that originally worked well in the winserver+Apache environment was migrated to Alibaba Cloud (environment: Ubuntu 64-bit | PHP5.4 | Nginx1.6) but frequently received 404, 403, and could only access CI routes.php There were problems such as the default controller set in . Later, I checked online and found out that it might be a problem with the routing settings. After much fiddling, I finally solved the problem by following the settings below.

1. Modify website configuration file

<span>server {
 2     listen 80;
 3     server_name<span> example.com</span>;//自己的域名
 4 
 5     root <span>/alidata/www/example</span>;//网站目录
 6     index index.php index.htm index.html;
 7 
 8     location / {
 9             try_files $uri $uri/ /index.php;
10     }
11 
12     location /index.php{
13         fastcgi_pass  127.0.0.1:9000;
14         fastcgi_param SCRIPT_FILENAME <span>/alidata/www/example/index.php</span>;
15       <span>  fastcgi_param PATH_INFO $fastcgi_path_info;</span>
16         fastcgi_split_path_info ^(.+\.php)(.*)$;
17         fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
18         include  fastcgi.conf;
19     }
20 
21 }</span>

2. Modify CI’s config.php file

$config['base_url'] = 'http://example.com/';

$config['uri_protocol'] = 'PATH_INFO';//It seems that REQUEST_URI will also work

$config['index_page'] = '';

3. Set read and write permissions (777) for the website root directory and the following directories

4. Restart nginx

The above introduces the configuration of the codeigniter framework under Nginx, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn