CakePHP在一个使用nginx的子目录中(重写规则?)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CakePHP在一个使用nginx的子目录中(重写规则?),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3632字,纯文字阅读大概需要6分钟。
内容图文
![CakePHP在一个使用nginx的子目录中(重写规则?)](/upload/InfoBanner/zyjiaocheng/963/629bf31ff55242ddadeb4ccc3440678c.jpg)
我设法让这个工作回来了一段时间,但是回到我开始的cakephp项目时,似乎我最近对nginx所做的任何改变(或者最近的更新)都破坏了我的重写规则.
目前我有:
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 localhost;
location / {
root html;
index index.php index.html index.htm;
}
location /basic_cake/ {
index index.php;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/basic_cake/(.+)$/basic_cake/index.php?url=$1 last;
break;
}
}
location /cake_test/ {
index index.php;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/cake_test/(.+)$/cake_test/index.php?url=$1 last;
break;
}
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php${
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 8081;
server_name localhost;
root /srv/http/html/xsp;
location / {
index index.html index.htm index.aspx default.aspx;
}
location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)${
fastcgi_pass 127.0.0.1:9001;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
我遇到的问题是css和图像不会从webroot加载.相反,如果我访问http://localhost/basic_cake/css/cake.generic.css,我会得到一个页面告诉我:
CakePHP: the rapid development php
framework Missing ControllerError: CssController could not be
found.Error: Create the class CssController
below in file:
app/controllers/css_controller.phpNotice: If you want to customize this
error message, create
app/views/errors/missing_controller.ctp
CakePHP: the rapid development php
framework
有没有人对如何解决这个问题有任何想法?
(我在ServerFault上发布了这个,但我有这种感觉,与此相比,没有多少人检查该网站,所以我可能不应该打扰…)
解决方法:
我设法通过将cake.base参数添加到cakephp配置而不是使用App.baseUrl(查看dispatcher.php中的代码)来解决这个问题.
所以,假设我有/ var / www / html / cakeprj中的cakephp副本,我的WWWROOT是/ var / www / html:
> nginx主机配置
# that's for all other content on the web host
location / {
root /var/www/html;
autoindex off;
index index.php index.html index.htm;
...
}
# that's for cakephp
location /cakeprj {
rewrite ^/cakeprj$/cakeprj/ permanent;
rewrite ^/cakeprj/(.+)$/$1 break;
root /var/www/html/cakeprj/app/webroot;
try_files $uri /$uri/ @cakephp;
}
# that's for all other php scripts on the web host
location ~ \.php${
root /var/www/html;
fastcgi_pass unix:/var/lib/fcgi/php-fcgi.socket;
...
include /etc/nginx/fastcgi_params;
}
# that's for cakephp execution
location @cakephp {
set $q $request_uri;
if ($request_uri ~ "^/cakeprj(.+)$") {
set $q $1;
}
fastcgi_param SCRIPT_FILENAME /var/www/html/cakeprj/app/webroot/index.php;
fastcgi_param QUERY_STRING url=$q;
fastcgi_pass unix:/var/lib/fcgi/php-fcgi.socket;
include /etc/nginx/fastcgi_params;
}
> app / config / core.php中的cakephp配置
Configure::write('App.base', '/cakeprj');
Configure::write('App.baseUrl', '/cakeprj/'); // seems like it doesn't matter anymore
…并且瞧 – 你正确地为nginx服务cakephp静态文件,正确地传递给cakephp调度程序的url以及正确生成url的cakephp.
附:如果你的nginx不支持try_files我相信它的配置可以用if条件和另一个重写来重写.
内容总结
以上是互联网集市为您收集整理的CakePHP在一个使用nginx的子目录中(重写规则?)全部内容,希望文章能够帮你解决CakePHP在一个使用nginx的子目录中(重写规则?)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。