Rails-没有路由匹配[GET]“ /index.html”(对于所有路由)

问题描述 投票:1回答:2

我正在尝试将我的Rails应用程序第一次部署到暂存环境。我很确定这是Apache / Passenger的问题,但我不确定该在哪里修复它。我可能只需要在conf文件中添加一条规则,但是我不知道该规则是什么。也许是某种重写规则,因为它似乎正在寻找文件而不是解析路由?

问题是:对于每条单一路线,似乎都是将其在“幕后”转换为“ /index.html”-无论我尝试使用“ / api / v1”还是“ / api / v1 / users”还是“ / api / v1 / channels / authorize”(或其他任何文件)。

apache2 / access.log文件似乎显示正确传递的路由:

[07/Dec/2019:18:23:15 +0000] "GET /api/v1/channels/authorize HTTP/1.1" 500 41024 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"

并且apache2 / error.log文件未显示任何错误。


这是我的conf文件。我正在使用别名在两个单独的应用程序之间进行解析(/ api / *进入Rails后端,其他都进入VueJS前端-我知道我可以将客户端嵌入到Rails公用目录中,但是我我出于自己的原因这样做)。

<VirtualHost *:443>
    ServerName <my url>
    DocumentRoot /path/to/client

     # configure error logs
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

     # Passenger config stuff
    PassengerEnabled off
    PassengerRuby /path/to/ruby
    PassengerAppEnv development
    PassengerStartTimeout 400


     # if the route matches https://<domain>/api/*
      # then point to the Rails API app
      # (and use Passenger to serve it)
    Alias /api /path/to/railsapp/public
     # configuration for the /api routes
      # basically just enable Passenger and tell it where to point to
    <Location /api>
        PassengerEnabled on
        PassengerBaseURI /
        PassengerAppRoot /path/to/railsapp
    </Location>
    <Directory /path/to/railsapp/public>
        Allow from all
        Options -MultiViews
        Require all granted

#       RailsEnv test
    </Directory>

     # for EVERYTHING ELSE, point to the VueJS client app
    <Location />
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . /index.html [L]
    </Location>

     # and of course enable SSL and point to the certs
    SSLEngine on
    SSLCertificateKeyFile /path/to/key
    SSLCertificateFile /path/to/cert
    SSLCertificateChainFile /path/to/chain-file

</VirtualHost>

这是我第一次与乘客做任何事情。我试图将我在网上找到的示例中的内容拼凑起来,但是很可能我一路上错过了一些内容。

ruby-on-rails apache passenger
2个回答
0
投票

尝试将PassengerBaseURI /下的<Location /api>更改为PassengerBaseURI /api


0
投票

所以我已经弄清楚了。以下代码块中的RewriteRule将应用于所有内容:

<Location / >
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.html [L]
</Location>

((Vue中的每条路线都被改写回index.html文件-但Rails不会这样做。

因此,在最终弄清楚我可以简单地将RewriteCond添加到规则集中以排除对api/*的所有调用之前,我尝试了一些不同的工作

所以新的块是:

<Location / >
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/api/*        ## THIS IS THE LINE TO ADD!
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.html [L]
</Location>

那一行是我必须添加到apache conf文件中的全部内容,才能使其正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.