AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 32070
Accepted
seanl
seanl
Asked: 2009-06-27 01:15:44 +0800 CST2009-06-27 01:15:44 +0800 CST 2009-06-27 01:15:44 +0800 CST

cakephp & nginx 配置/重写规则

  • 772

嗨,有人请帮帮我,我也在 stackoverflow 上问过这个问题,但没有得到太多回应,并且正在争论它是编程还是服务器相关。

我正在尝试在使用 Fact CGI 运行 Nginx 的 Centos 服务器上设置 cakephp 环境。我已经在服务器上运行了一个 wordpress 站点和一个 phpmyadmin 站点,所以我正确配置了 PHP。

我的问题是我无法在我的虚拟主机中正确设置重写规则,以便蛋糕正确呈现页面,即样式等。我已经尽可能多地在谷歌上搜索,下面列出的网站的主要共识是我需要制定以下重写规则

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 中运行 cake,这不是我想要做的。我对每个站点都有一个标准设置,即每个站点一个文件夹,其中包含以下文件夹日志、备份、私人和公共。公共场所 nginx 正在寻找其要服务的文件,但我私下安装了蛋糕,并在公共链接回 /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 并将其连接到我的数据库,但是这个页面没有样式,所以在我继续之前,我想正确配置它。我究竟做错了什么………。

谢谢海尔

centos php nginx cakephp
  • 3 3 个回答
  • 9777 Views

3 个回答

  • Voted
  1. Best Answer
    Scott M Likens
    2009-06-30T12:41:53+08:002009-06-30T12:41:53+08:00

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

    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;
        }
    
    }
    
    • 2
  2. hegemon
    2009-06-27T03:21:53+08:002009-06-27T03:21:53+08:00

    您的 php 文件被“~ .php$”位置捕获,它是唯一有效的文件。

    这不起作用:

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

    因为你提供系统路径,你应该提供 URI 路径。与重写规则相同。我看到您的配置类似于 apache :) 所以这可能是您要寻找的东西:

    location /root_of_my_site {
       alias home/public_html/app.domain.com/...
    }
    
    • 0
  3. lexsys
    2009-06-27T04:36:28+08:002009-06-27T04:36:28+08:00
    
    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.

    祝你好运!

    • 0

相关问题

  • 使用Passenger时使用Nginx over Apache with Rails的优缺点是什么

  • 如何在 IIS 6 中免费重写 url (ala mod_rewrite)?

  • 阿帕奇的替代品

  • mod_rewrite 不转发 GET 参数

  • 更改 PHP 的默认配置设置?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve