Nginx下支持Thinkphp URL Rewrite的配置示例
概述
Nginx服务器现在已经成为相当流行的开源Web服务器,很多生产环境也都在使用Nginx服务器。现在做项目大多数时候都是在使用ThinkPHP,但是Nginx默认不支持ThinkPHP的pathinfo模式,需要进行一定的配置。
Nginx配置文件
#
#Thedefaultserver
#
server{
listen80default_server;
#server_namewww.example.com;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
#Loadconfigurationfilesforthedefaultserverblock.
include/etc/nginx/default.d/*.conf;
#location/{
#root/usr/share/nginx/html;
#indexindex.htmlindex.htm;
#}
location/{
root/var/www/project_name;
indexindex.htmlindex.php;
if(!-e$request_filename){
rewrite^(.*)$/index.php?s=$1last;
}
}
error_page404/404.html;
location=/404.html{
root/usr/share/nginx/html;
}
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
root/usr/share/nginx/html;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.php${
root/var/www/project_name;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}
}
总结
做个备份,方便以后查看:)