PHP的Symfony和CodeIgniter框架的Nginx重写规则配置
Symfony
Symfony国外很流行的php框架,目前国内用的相对较少,但是一定会在国内火起来.nginx重写规则如下
server{ server_namejb51.netwww.nhooo.com; root/data/site/www.nhooo.com; location/{ #trytoservefiledirectly,fallbacktorewrite try_files$uri@rewriteapp; } location@rewriteapp{ #rewritealltoapp.php rewrite^(.*)$/app.php/$1last; } location~^/(app|app_dev|config).php(/|$){ fastcgi_passunix:/var/run/php5-fpm.sock;#改成你对应的FastCGI fastcgi_split_path_info^(.+.php)(/.*)$; includefastcgi_params; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; fastcgi_paramHTTPSoff; } error_log/data/logs/nginx/www.nhooo.com_error.log; }
重启nginx即可
CodeIgniter
CodeIgniter,即被很多人简称为CI的高人气PHP框架,其中文社区也比较活跃,来看一下CI的rewrite写法:
server{ listen80; server_namejb51.netwww.nhooo.com; root/data/site/www.nhooo.com; indexindex.php; error_loglog/error.log; #setexpirationofassetstoMAXforcaching location~*.(ico|css|js|gif|jpe?g|png)(?[0-9]+)?${ expiresmax; log_not_foundoff; } #maincodeigniterrewriterule location/{ try_files$uri$uri//index.php; } #phpparsing location~.php${ root/data/site/jb51.net/; try_files$uri=404; fastcgi_passunix:/tmp/php5-fpm.sock;#改成对应的FastCGI fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; fastcgi_buffer_size128k; fastcgi_buffers2564k; fastcgi_busy_buffers_size256k; fastcgi_temp_file_write_size256k; } }
修改CI(CodeIgniter)配置文件config.php
$config['base_url']="https://www.nhooo.com/"; $config['index_page']=""; $config['uri_protocol']="REQUEST_URI";