【问题标题】:Passenger always shows "Index of"乘客总是显示“索引”
【发布时间】:2013-06-18 15:18:14
【问题描述】:

我已经坚持这个问题一个星期了。我无法通过 Apache2 的乘客模块运行我的 Rails 应用程序。我使用 Ubuntu 12.04 64 位和 Rails 3.2.8 Ruby 1.9.3 Passenger 4.0.5。 我的 Rails 应用程序位于 /home/sarunint/cafe_grader/web

这是我的 /etc/apache2/sites-available/default

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
    RailsBaseURI /grader
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

这是我的 /etc/apache2/httpd.conf

LoadModule passenger_module /home/sarunint/.rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
PassengerRoot /home/sarunint/.rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.5
PassengerRuby /home/sarunint/.rvm/wrappers/ruby-1.9.3-p392/ruby

PS。如果这是一个重复的主题,请随时告诉我:)

谢谢

更新

我刚刚注意到,当我重新启动 Apache2 时,我得到了这个:

sarunint@server1:~$ sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                 
[Tue Jun 18 23:05:56 2013] [warn] module passenger_module is already loaded, skipping
... waiting [Tue Jun 18 23:05:57 2013] [warn] module passenger_module is already loaded, skipping

更新 2 在@mohamed-abshir 做了一些 grep 之后,我得到了以下几行:

sarunint@server1:/etc/apache2$ grep -irl "LoadModule passenger_module" .
./mods-available/passenger.load
./mods-enabled/passenger.load
./httpd.conf

谢谢。

更新 3

which ruby 打印: /home/sarunint/.rvm/rubies/ruby-1.9.3-p392/bin/ruby

cat /etc/apache2/mods-enabled/passenger.load 打印: LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so

这是你想要的文件:

<VirtualHost *:80>
        ServerName sarunint.uni.me
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        RailsBaseURI /grader
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
    <Directory /home/sarunint/cafe_grader/web/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

【问题讨论】:

标签: ruby-on-rails apache passenger


【解决方案1】:

自乘客 2.0 以来,它不遵循 DocumentRoot 的符号链接,乘客检测其 ruby​​ on rails 应用程序是否正在寻找位于 DocumentRoot 目录后面一层的 config.ru 的方式。假设DocumentRoot/var/www/public,它将在/var/www 中搜索config.ru 文件。但是,如果 www 是指向另一个位置的符号链接,假设 /var/www -&gt; /home/ruby/my_app/public 它不会跟随符号链接,因此无法找到文件并且不会处理请求。

要解决此问题,您可以添加到httpd.conf

PassengerResolveSymlinksInDocumentRoot on

【讨论】:

    【解决方案2】:

    如果您的站点名称是“example.com”,那么在 ServerAdmin webmaster@localhost 行下,您需要:

    ServerName  example.com
    ServerAlias www.example.com  #not necessary
    

    DocumentRoot 应该指向您的站点文件并变为:

    DocumentRoot home/sarunint/cafe_grader/web/public
    

    您的目录块应该是:

    <Directory /home/sarunint/cafe_grader/web/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    

    然后重新启动 apache 并转到您的站点 url。 我没有检查你的 Ruby 指针,但基本上在命令行上,当“哪个 ruby​​”打印出来的位置时,应该与你在上面发布的作为 ruby​​ 解释器的内容相匹配。

    更新

    操作员发布了关于乘客模块再次加载的说明。 当通过 rvm 正常安装乘客时,它会告诉您要运行哪些命令以及将您上面发布的 3 行代码放在哪里(它们通常位于 conf.d/passenger.conf 下)。似乎有“乘客模块加载了两次”所以去你的 Apache 目录搜索它:

     cd /etc/apache2/
    grep -irl "LoadModule passenger_module" . # this searchs those words in current dir(don't remove the dot = current dir"
    

    【讨论】:

    • 感谢您的回复,但我想将此应用程序作为目录运行,用户需要转到 my.domain/grader 才能访问该应用程序。
    • 上面应该没有问题。在 Apache 语言中,“/grader”是路径。 Apache 必须首先响应“my.domain”,然后在您的请求中查找路径。 块只是为您的文件夹设置权限和内容。在 Rails 中,您必须将 DocRoot -> 指向 /yourApp/public。
    • 我更新了答案。我之前发布的东西,确保 Apache & 指向你的 Rails 应用程序——所以这些很重要。最新的说明是关于乘客模块正常工作 - 小问题。
    • 我做到了,请在主帖中查看结果。
    • 您能否发布以下两个命令的结果并更新 容器:“cat /etc/apache2/mods-enabled/passenger.load”“which ruby​​”跨度>
    【解决方案3】:
    <VirtualHost *:80>
    
    #this isn't working, it's running under drew
    PassengerDefaultUser www-data
    
    ServerAdmin youremail@mail.com
    ServerName mysite.localhost.com
    
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    
    DocumentRoot /var/www/rails/ridcyDevelopment/public
    RailsEnv development
    #RailsBaseURI /
    
    <Directory /var/www/rails>
      Options Indexes FollowSymLinks -MultiViews +ExecCGI
      AllowOverride all
      Allow from All
    </Directory>
    

    【讨论】:

    • 如果有一些解释,这将是一个更好的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 2022-01-20
    相关资源
    最近更新 更多