2013-02-05 67 views
2

目前我正在用nginx的cakephp工作。我在運行Nginx和Fact CGI的Centos服務器上設置了一個cakephp環境。問題是我不能在我的虛擬主機中設置正確的重寫規則,以便蛋糕正確地呈現頁面,即使用樣式等等。 我.conf文件是 -如何在nginx中配置cakephp

#The default server 

server {  
listen 80 default_server;  
server_name 1 23.123.123.123; 

#charset koi8-r; 

#access_log logs/host.access.log main; 

location/{ 
    root /usr/share/nginx/html; 
    index index.php index.html index.htm; 
} 


error_page 404    /404.html; 
location = /404.html { 
    root /usr/share/nginx/html; 
} 

# redirect server error pages to the static page /50x.html 
# 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /usr/share/nginx/html; 
} 

# proxy the PHP scripts to Apache listening on 127.0.0.1:80 
# 
#location ~ \.php$ { 
# proxy_pass http://127.0.0.1; 
#} 


# 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 /usr/share/nginx/html$fastcgi_script_name; 
    include  fastcgi_params; 
} 

# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
location ~ /\.ht { 
    deny all; 
} 
} 

回答

2

使用打擊代碼

location/{ 
    if (-f $request_filename) { 
     break; 
    } 
    if (!-f $request_filename) { 
     rewrite ^/(.+)$ /index.php?url=$1 last; 
     break; 
    } 

    set $new_uri $uri; 
} 
0

這個工作對我來說:加入

server { 
    listen 80 ; 

    server_name example.com;  

    root /www/example.com/app/webroot; 
    index index.html index.php; 

    location/{ 
    try_files $uri $uri/ /index.php?$uri&$args; 
    set $new_uri $uri; 
    } 

    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 

    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    fastcgi_param PATH_INFO $new_uri; 
    } 

    location ~ /(\.ht|\.git|\.svn) { 
    deny all; 
    } 

} 

$new_uri規則作出一些特殊的路線在我的網站工作,也許這將不適用於你,但請注意,CakePHP假定已設置PATH_INFO,因此這些規則不會將其留在那裏。

希望它有幫助。

3

Luchomolina的回答下面讓我開始了正確的方向。但是,CSS和JS文件停止處理不是頂級URL的URL,例如/職位工作,但/職位/ title123沒有。

這是結束了,我的工作:

location/{ 
    if (-f $request_filename) { 
     break; 
    } 
    if (!-f $request_filename) { 
     rewrite ^/(.+)$ /index.php?url=$1 last; 
     break; 
    } 

    set $new_uri $uri; 
}