【问题标题】:Nginx CakePHP rewrite issueNginx CakePHP 重写问题
【发布时间】:2016-01-12 21:42:05
【问题描述】:

我一直在尝试让带有 CakePHP 的 Nginx 运行,但在重写方面没有成功。我已经阅读了大量的文章,并没有发现我的配置文件有任何问题。

Nginx Webroot:/usr/share/nginx/html

CakePHP 安装:/usr/share/nginx/html/cakephp

错误:您的服务器上未正确配置 URL 重写。

  1. 帮我配置一下
  2. 我不/不能使用 URL 重写

配置文件:

server {
        listen 80;

        root /usr/share/nginx/html;
        index index.php index.html index.htm;

        server_name localhost;

        location / {
                try_files $uri $uri/ /index.html;
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

        # Deny access to .htaccess files,
        location ~ /(\.ht|\.git|\.svn) {
                deny  all;
        }
}

【问题讨论】:

  • 什么不起作用?是 /doc/ 位置块吗?
  • Cakephp 将启动其起始页,并显示有关未正确配置重写的错误。结果页面上没有css、图片等。

标签: cakephp nginx


【解决方案1】:

对于虚拟域,这将起作用。

location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    rewrite ^/$ /app/webroot/ break;
    rewrite ^(.*)$ /app/webroot/$1 break;

}
location /app/ {
    rewrite ^/$ /webroot/ break;
    rewrite ^(.*)$ /webroot/$1 break;
}
location /app/webroot/ {
    if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
    }
}   

【讨论】:

    【解决方案2】:

    你的问题来了

    try_files $uri $uri/ /index.html
    

    编辑:

    我只是四处寻找 cake php,它的路由与 cake php 有点不同,试试这个

    try_files $uri $uri/ /index.php?url=$request_uri;
    

    然后重新加载配置

    【讨论】:

    • 嗨,我这样做了,现在接收页面无法显示
    • 嗨 Mohammad,我做到了,但仍然无法解决问题。我在 AWS 上创建了服务器的副本。如果你能自己看看,看看我哪里出错了,那就太好了。如果您可以查看,我可以将克隆服务器上的详细信息发送给您。
    猜你喜欢
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多