【问题标题】:how to configure cakephp in nginx如何在 nginx 中配置 cakephp
【发布时间】:2013-01-20 05:30:16
【问题描述】:

目前我正在使用 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;
}
}

【问题讨论】:

    标签: cakephp nginx memcached centos vhosts


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      使用打击代码

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

      【讨论】:

        【解决方案3】:

        这对我有用:

        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 已设置,因此将这些规则留在那里不会有害.

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-12-02
          • 1970-01-01
          • 2010-11-05
          • 2012-11-07
          • 2021-10-28
          • 2014-08-24
          • 2021-10-22
          • 2020-10-17
          相关资源
          最近更新 更多