Nginx配置PHP的Yii與CakePHP框架的rewrite規(guī)則示例
更新時(shí)間:2016年01月13日 18:18:37 投稿:goldensun
這篇文章主要介紹了Nginx配置PHP的Yii與CakePHP框架的rewrite規(guī)則示例,是這兩款高人氣框架使用Nginx的關(guān)鍵配置點(diǎn),需要的朋友可以參考下
Yii的Nginx rewrite
如下為nginx yii的重寫
server {
set $host_path "/data/site/www.dhdzp.com";
access_log /data/logs/nginx/www.dhdzp.com_access.log main;
server_name jb51.net www.dhdzp.com;
root $host_path/htdocs;
set $yii_bootstrap "index.php";
# define charset
charset utf-8;
location / {
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
# deny access to protected directories
location ~ ^/(protected|framework|themes/w+/views) {
deny all;
}
#avoid processing of calls to unexisting static files by yii
location ~ .(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
# prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
location ~ /. {
deny all;
access_log off;
log_not_found off;
}
# php-fpm configuration using socket
location ~ .php {
fastcgi_split_path_info ^(.+.php)(.*)$;
#yii catches the calls to unexising PHP files
set $fsn /$yii_bootstrap;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成你對(duì)應(yīng)的FastCGI
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
#PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
## Tweak fastcgi buffers, just in case.
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
配置完了別忘了重啟Nginx。
CakePHP的Nginx重寫規(guī)則
依然簡(jiǎn)單粗暴,直接上代碼例子,nginx重寫規(guī)則如下
server {
listen 80;
server_name www.dhdzp.com;
root /data/site/www.dhdzp.com;
index index.php;
access_log /data/logs/nginx/www.dhdzp.com_accerss.log;
error_log /data/logs/nginx/www.dhdzp.com_error.log;
# main cakephp rewrite rule
location / {
try_files $uri $uri/ /index.php?$uri&$args;
}
location ~ .php$ {
root /data/site/www.dhdzp.com;
try_files $uri =404;
fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成你對(duì)應(yīng)的FastCGI
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
重啟nginx即可
相關(guān)文章
Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例
這篇文章主要介紹了Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例,包括一個(gè)用perl腳本來實(shí)現(xiàn)的方法,需要的朋友可以參考下2016-01-01
WordPress與Drupal的Nginx配置rewrite重寫規(guī)則示例
這篇文章主要介紹了WordPress與Drupal的Nginx配置重寫規(guī)則示例,文中介紹的rewrite寫法簡(jiǎn)單而突出配置重點(diǎn),需要的朋友可以參考下2016-01-01
詳解php+nginx 服務(wù)發(fā)生500 502錯(cuò)誤排查思路
這篇文章主要介紹了詳解php+nginx 服務(wù)發(fā)生500 502錯(cuò)誤排查思路,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Nginx實(shí)現(xiàn)ChatGPT?API代理步驟
這篇文章主要為大家介紹了Nginx實(shí)現(xiàn)ChatGPT?API代理步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05

