大家好,请帮帮我,我正在尝试在运行 Nginx 和 Fact CGI 的 Centos 服务器上设置 cakephp 环境。我已经在服务器上运行了一个 WordPress 站点和一个 phpmyadmin 站点,因此我已经正确配置了 PHP。
我的问题是我无法在我的虚拟主机中正确设置重写规则,以便 cake 正确渲染页面,即样式等。我尽可能多地用谷歌搜索,下面列出的网站的主要共识是我需要制定以下重写规则
location / {
root /var/www/sites/somedomain.com/current;
index index.php index.html;
# If the file exists as a static file serve it
# directly without running all
# the other rewrite tests on it
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
}
http://blog.getintheloop.eu/2008/4/17/nginx-engine-x-rewrite-rules-for-cakephp http://blog.getintheloop.eu/2008/4/17/nginx-engine-x-rewrite-rules-for-cakephp
问题是这些重写假设你直接从 webroot 运行 cake,这不是我想要做的。我对每个站点都有一个标准设置,即每个站点一个文件夹,其中包含以下文件夹日志、备份、私有和公共。公共是 nginx 正在寻找其文件来服务的地方,但我私下安装了 cake,并在公共链接回 /private/cake/ 中的符号链接
这是我的虚拟主机
server {
listen 80;
server_name app.domain.com;
access_log /home/public_html/app.domain.com/log/access.log;
error_log /home/public_html/app.domain.com/log/error.log;
#configure Cake app to run in a sub-directory
#Cake install is not in root, but elsewhere and configured
#in APP/webroot/index.php**
location /home/public_html/app.domain.com/private/cake {
index index.php;
if (!-e $request_filename) {
rewrite ^/(.+)$ /home/public_html/app.domain.com/private/cake/$1 last;
break;
}
}
location /home/public_html/app.domain.com/private/cake/ {
index index.php;
if (!-e $request_filename) {
rewrite ^/(.+)$ /home/public_html/app.domain.com/public/index.php?url=$1 last;
break;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/public_html/app.domain.com/private/cake$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
现在,就像我说的,我可以看到 cake 的主 index.php 并将其连接到我的数据库,但该页面没有样式,因此在继续之前,我想正确配置它。我究竟做错了什么?
谢谢肖尔
乍一看,您的问题可能是您没有将 nginx 指向应用程序的 webroot。部署到根 cake 文件夹实际上并不是在任何 Web 服务器下进行的方法。
以下是我使用运行 Cake 应用程序的完整服务器块。实际上,我只有前四行,然后包含来自单独文件“cakephp.inc”的其余部分。
“fastcgi_param SERVER_NAME $host;”行上的注释。这是因为我的一些应用程序使用 $_SERVER['SERVER_NAME'] 并且它在 nginx 中的含义与在 Apache 中的含义不同。如果你的服务器有多个定义的 server_name(s),nginx 总是将第一个传递给 php。
server {
server_name cakeapp.example.com;
root /var/www/vhosts/cake/app/webroot;
access_log /var/log/nginx/cakeapp.access.log;
error_log /var/log/nginx/cakeapp.error.log;
listen 80;
rewrite_log on;
# rewrite rules for cakephp
location / {
index index.php index.html;
# If the file exists as a static file serve it
# directly without running all
# the other rewite tests on it
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
}
location ~* \favicon.ico$ {
expires 6m;
}
location ~ ^/img/ {
expires 7d;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_param SERVER_NAME $host;
}
location ~ /\.ht {
deny all;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)