2

目前我正在使用 nginx 开发 cakephp。我在使用 Fact CGI 运行 Nginx 的 Centos 服务器上设置了 cakephp 环境。问题是我无法在我的虚拟主机中设置正确的重写规则,以便蛋糕正确呈现页面,即样式等。我的 .conf 文件为 -

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

3 回答 3

3

Luchomolina 在下面的回答让我朝着正确的方向开始。但是,CSS 和 JS 文件停止在不是顶级 URL 的 URL 上工作,例如 /posts 工作但 /posts/title123 没有。

这最终为我工作:

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

   set $new_uri $uri;
} 
于 2013-09-27T17:00:18.977 回答
2

使用打击代码

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

   set $new_uri $uri;
} 
于 2015-12-05T08:22:59.973 回答
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已设置,因此这些规则不会损害将其留在那里。

希望能帮助到你。

于 2013-02-05T17:43:09.970 回答