网站一直要求下载 ruby​​ 文件?

网站一直要求下载 ruby​​ 文件?

我是 ruby​​ 开发的新手。我尝试在 Ubuntu 14.04 上安装 phusion Passenger 并将其与 apache 集成。

我完成了本页的第 2.3 步: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html

但是当我访问类似的 URL 时http://192.168.0.105/suburl/home.rb,浏览器会下载 rb 文件而不是将其作为网页提供。

我迷失在所有说明中。有人能建议我下一步该怎么做才能让我的 home.rb 简单地运行吗 puts "hello world"

这是我的 /etc/apache/sites-enabled/000-default

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我看到passenger.load也在mods-enabled目录中。

答案1

通常,当您的浏览器为您提供文件供下载时,这意味着 Web 服务器无法将文件识别为动态内容。php/python/ruby 也是如此...

首先保持简单。选择 Apache 或 Nginx 来运行您的乘客模块。

如果选择 apache,请启用 Ubuntu Universe 存储库,然后运行:

apt-get install libapache2-mod-passenger

另一方面,如果您选择 nginx,则必须安装具有内置支持的 nginx 版本:

apt-get install ruby-passenger

另外,你的项目必须至少有 3 个目录

/var/www/myproject
/var/www/myproject/public
/var/www/myproject/tmp

和 1 个文件:

/var/www/myproject/config.ru

您需要将 DocumentRoot 设置为“public”,但您的代码会从 config.ru 开始加载。因此,这是示例 apache Vhost:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/myproject/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

从您链接的文档中查看 4.1。

相关内容