Nginx配置PHP的Yii與CakePHP框架的rewrite規(guī)則示例
更新時間:2016年01月13日 18:18:37 投稿:goldensun
這篇文章主要介紹了Nginx配置PHP的Yii與CakePHP框架的rewrite規(guī)則示例,是這兩款高人氣框架使用Nginx的關(guān)鍵配置點,需要的朋友可以參考下
Yii的Nginx rewrite
如下為nginx yii的重寫
server { set $host_path "/data/site/chabaoo.cn"; access_log /data/logs/nginx/chabaoo.cn_access.log main; server_name jb51.net chabaoo.cn; 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; # 改成你對應的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ī)則
依然簡單粗暴,直接上代碼例子,nginx重寫規(guī)則如下
server { listen 80; server_name chabaoo.cn; root /data/site/chabaoo.cn; index index.php; access_log /data/logs/nginx/chabaoo.cn_accerss.log; error_log /data/logs/nginx/chabaoo.cn_error.log; # main cakephp rewrite rule location / { try_files $uri $uri/ /index.php?$uri&$args; } location ~ .php$ { root /data/site/chabaoo.cn; try_files $uri =404; fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成你對應的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如何配置同一個端口轉(zhuǎn)發(fā)多個項目
這篇文章主要介紹了nginx如何配置同一個端口轉(zhuǎn)發(fā)多個項目問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01Nginx如何配置根據(jù)路徑轉(zhuǎn)發(fā)詳解
Nginx是作為一個反向代理,轉(zhuǎn)發(fā),和負載均衡的服務器,也可以用于分布式,下面這篇文章主要給大家介紹了關(guān)于Nginx如何配置根據(jù)路徑轉(zhuǎn)發(fā)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-07-07Mac中使用Nginx實現(xiàn)80端口轉(zhuǎn)發(fā)8080端口
端口轉(zhuǎn)發(fā)(Port forwarding),有時被叫做隧道,是安全殼(SSH) 為網(wǎng)絡安全通信使用的一種方法。端口轉(zhuǎn)發(fā)是轉(zhuǎn)發(fā)一個網(wǎng)絡端口從一個網(wǎng)絡節(jié)點到另一個網(wǎng)絡節(jié)點的行為,其使一個外部用戶從外部經(jīng)過一個被激活的NAT路由器到達一個在私有內(nèi)部IP地址(局域網(wǎng)內(nèi)部)上的一個端口2017-09-09如何使用Nginx和uwsgi在自己的服務器上部署python的flask項目
Nginx 是一個高性能的 HTTP 和反向代理服務,其特點是占有內(nèi)存少,并發(fā)能力強,事實上nginx的并發(fā)能力在同類型的網(wǎng)頁服務器中表現(xiàn)較好,這篇文章主要介紹了如何使用Nginx和uwsgi在自己的服務器上部署python的flask項目,需要的朋友可以參考下2023-11-11