【问题标题】:Router not working (Heroku + Nginx + PHP Phalcon)路由器不工作(Heroku + Nginx + PHP Phalcon)
【发布时间】:2018-11-20 09:37:08
【问题描述】:

我不明白为什么 mvc 路由不起作用。

当我访问主页时,所有的css和js都被加载了。

"GET /css/main.css HTTP/1.1" 304

但是当我访问任何其他控制器时,我得到了:

method=GET path="/transaction/add"
[error] open() "/app/public/transaction/add" failed (2: No such file or directory)
"GET /transaction/add HTTP/1.1" 404

这是我的过程文件

--Procfile--
web: vendor/bin/heroku-php-nginx public/

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to app.php
    rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/(app|app_dev|config)\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

我真的迷路了。

【问题讨论】:

  • 对不起,我使用 Apache,但这似乎是矛盾的:# rewrite all to app.php VS rewrite ^(.*)$ /index.php/$1 last;您可以尝试使用 app.php 而不是 index.php,或者使用 public/index.php
  • @KyleK,只是为了更新,我做了一些更改,但还没有。

标签: heroku nginx phalcon


【解决方案1】:

这应该可行:

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to app.php
    rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/index\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

【讨论】:

  • 不幸的是,我已经尝试过了,但没有成功。也许问题是 Procfile 没有读取我的 /public/index.php,但还不确定。
【解决方案2】:

尝试按照文档中的说明进行操作:http://docs.phalconphp.com/fr/latest/reference/nginx.html

server {

    listen   80;
    server_name localhost.dev;

    index index.php index.html index.htm;
    set $root_path '/var/www/phalcon/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

【讨论】:

  • 我做了,但我得到了“未启用 Mod-Rewrite。请在您的 Web 服务器上启用重写 url 以继续”。那是我的第一个问题。有什么想法吗?
  • 你的路径是什么(而不是 /var/www/phalcon/public)并且它是否包含 index.php?
  • 我已经执行了“heroku run bash”,我看到路径是“app/public”,里面有 index.php。只是为了清楚我可以获得的应用程序文件夹最大根目录,其中没有包含项目名称的文件夹。
  • app可能是FTP根而不是机器根,必须将/var/www/phalcon/public替换为绝对公共路径,显示dirname(__FILE__)即可获取。
  • 同样的事情:“/app”。还有其他想法吗?
猜你喜欢
  • 1970-01-01
  • 2014-07-10
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-12
  • 2017-08-18
相关资源
最近更新 更多