转自:
nginx如何配置才能支持codeigniter ?
1. codeigniter的url美化去掉index.php
1 2 3 4 5 | location / { root html/gxtp; index index.php; try_files $uri $uri/ /index.php?$uri&$args; } |
2.与thinkphp一样codeigniter的url rewrite也是使用pathinfo来实现的,需要借助fastcgi_split_path_info来设置$_SERVER['PATHINFO']。
1 2 3 4 5 6 7 8 9 10 | location ~ ^.+.php { include fastcgi_params; root html/gxtp; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } |
codeigniter完整版nginx.conf规则
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.264.cn; location / { root html/kdw; index index.php; try_files $uri $uri/ /index.php?$uri&$args; } location ~ ^.+.php { include fastcgi_params; root html/kdw; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } } } |