Nginx CodeIgniter configuration Project (2)

Source: Internet
Author: User
Two CI project deployment methods for Nginx: rewrite and PATH_INFO. of course, the latter is relatively simple URL rewrite.
server { listen 8080; server_name www.xxx.com; root /Users/lch/work/www/ci; access_log /usr/local/var/log/access.log; error_log /usr/local/var/log/error.log; location ~ ^/(img|images|script|js|css|upload)/ { root /Users/lch/work/www/ci; break; } location ~ { if (!-e $request_filename) { # for /admin rewrite ^/(admin)$ /index.php?c=welcome&m=index&d=$1 break; # for /admin/index rewrite ^/(admin)/([a-zA-Z_]+)$ /index.php?c=$2&m=index&d=$1 break; # for /admin/account/login rewrite ^/(admin+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ /index.php?c=$2&m=$3&d=$1 break; ## for general URL rewrite ^/([a-zA-Z_]+)/([a-zA-Z_]+)/?(.*)$ /index.php?c=$1&m=$2 last; } root /Users/lch/work/www/ci; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

Description of the above configuration, because I created a folder named admin in application/controllers/to store the controller related to the background, therefore, it is more than a common path (corresponding to & d = admin. Here we can see that the rewrite method is insufficient. when there is a situation like admin, we need to add the corresponding rewrite rule.

PATH_INFO method
server { listen 8080; server_name www.xxx.com; root /Users/lch/work/kidulty/snap_www; access_log /usr/local/var/log/snap_access.log; error_log /usr/local/var/log/snap_error.log; location ~ ^/(img|images|script|js|css|upload)/ { root /Users/lch/work/kidulty/snap_www; break; } if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; } location ~ { set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } root /Users/lch/work/kidulty/snap_www; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; } } 

Note:

  • If the project URL is similar to http://www.xxx.com/index.php/user/profile, the following rewrite:
if (!-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; } 

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.