cakephp&nginxconfiguration/重写规则

嗨有人请帮助我,我也问过这个在stackoverflow,但没有得到太多的回应,并辩论是否是编程或服务器相关。

我正在尝试在运行Nginx和Fact CGI的Centos服务器上设置一个cakephp环境。 我已经有一个WordPress服务器上运行的一个WordPress站点和一个phpmyadmin网站,所以我已经正确configurationPHP

我的问题是,我不能在我的虚拟主机正确的重写规则设置,使蛋糕正确呈现页面,即样式等。 我已经尽可能多地search了一下,下面列出的站点的主要共识是我需要有下面的重写规则

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

问题是这些重写,假设你直接从webroot运行的蛋糕,这是不是我想要做的。 我有一个每个站点的标准设置,即每个站点包含以下文件夹日志,备份,私人和公共的一个文件夹。 公开的地方nginx正在寻找它的文件服务,但我有蛋糕安装在一个符号链接公共连接到/私人/蛋糕/

这是我的虚拟主机

 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; } } 

现在就像我说的,我可以看到主要的index.php蛋糕,并将其连接到我的数据库,但是这个页面没有样式,所以在我继续之前,我想正确configuration它。 我究竟做错了什么………。

感谢seanl

对于一个非常简单/干净,它与cakephp工作方法。 (我做了什么,使其工作,添加到configuration的集合)

 server { listen 80; server_name _; root /var/www/webapplication/app/webroot; if (-f $request_filename) { break; } if (!-f $request_filename) { rewrite ^/(.+)$ /index.php?url=$1 last; break; } location /favicon.ico { empty_gif; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /usr/nginx/conf/fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/webapplication/app/webroot/index.php; # $fastcgi_script_name; } } 

你的php文件被“〜.php $”位置捕获,并且是唯一可用的。

这不会工作:

 location /home/public_html/app.domain.com/private/cake/ 

因为你给系统path,你应该给URIpath。 与重写规则相同。 我看到你的configuration是apache像:)所以这可能是你要找的东西:

 location /root_of_my_site { alias home/public_html/app.domain.com/... } 
 location /cake { try_files $uri $uri/ @cakephp; } location = @cakephp { fastcgi_param SCRIPT_FILENAME /home/public_html/app.domain.com/private/cake/index.php; fastcgi_param QUERY_STRING url=$request_uri; fastcgi_pass 127.0.0.1:9000; include /etc/nginx/fastcgi_params; } 

这假定你通过http://apps.server.com/cakephp访问cakephp并且有nginx 0.7.x.

如果你有nginx 0.6.x,使用error_page 404 = @cakephp而不是try_files

祝你好运!