A WeChat official account that originally worked well in the winserver Apache environment was migrated to Alibaba Cloud in the background (environment: Ubuntu 64-bit | PHP5. 4 | Nginx1.6), but 404, 403 occurred frequently, and the default controller set in CI routes.php could only be accessed. Later, I checked online and found that it might be a routing setting issue. After much fiddling, I finally solved the problem with the following settings. .
1. Modify website configuration file
Copy code The code is as follows:
server {
Listen 80;
Server_name example.com;//Your own domain name
Root /alidata/www/example;//Website directory
index index.php index.htm index.html;
Location / {
try_files $uri $uri/ /index.php;
}
Location /index.php{
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /alidata/www/example/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(. .php)(.*)$;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
Include fastcgi.conf;
}
}
2. Modify CI’s config.php file
Copy code The code is as follows:
$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 is the entire content of this article. I hope it will help everyone to use the CI framework proficiently.