2013-06-18 18 views
1

我一直堅持這個問題一個星期。我無法讓我的Rails應用程序通過Apache2的乘客模塊運行。我使用Ubuntu 12.04 64位Rails 3.2.8 Ruby 1.9.3 Passenger 4.0.5。 我的Rails應用是的/ home/sarunint/cafe_grader /網絡乘客總是顯示「索引」

這是我的/ etc/apache2的/網站可用/默認

<VirtualHost *:80> 
ServerAdmin [email protected] 

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我得到這個:

[email protected]:~$ 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之後,我得到了這些行:

[email protected]:/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 [email protected] 

     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> 
+0

可能重複http://stackoverflow.com/questions/4113299/ruby-on-rails-服務器選項) – rcd

回答

-1

如果你的網站名稱爲「example.com」,那麼下的ServerAdmin網站管理員@本地線,你需要:

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

的DocumentRoot應該指向你的網站的文件,併成爲:

​​

你的目錄塊應:

<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解釋器匹配。

更新

該op發佈了一個關於再次加載的乘客模塊的註釋。 當乘客通過rvm正常安裝時,它會告訴您要運行哪些命令以及在哪裏放置上面發佈的三行代碼(它們通常位於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" 
+0

感謝您的迴應,但我想將此應用程序作爲目錄運行,用戶需要到my.domain/grader才能訪問應用程序。 –

+0

這應該不是上面的問題。在Apache語言中,「/ grader」是路徑。 Apache必須首先響應「my.domain」,然後在請求中查找路徑。 塊只是爲您的文件夾設置權限和內容。在Rails中,您必須將DocRoot - >指向/ yourApp/public。 –

+0

謝謝,請參閱主文章中的更新:) –

-2
<VirtualHost *:80> 

#this isn't working, it's running under drew 
PassengerDefaultUser www-data 

ServerAdmin [email protected].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> 
+0

如果它有一些解釋,這將是一個更好的答案 –

0

由於乘客2.0它不遵循DocumentRoot的符號鏈接,乘客的方式檢測,如果它的紅寶石on rails應用程序正在尋找config.ruDocumentRoot目錄之後的一個級別。假設DocumentRoot/var/www/public,它將在/var/www中搜索config.ru文件。但是,如果www是另一個位置的符號鏈接,假設/var/www -> /home/ruby/my_app/public它不會遵循sym鏈接,因此無法找到該文件並且不會處理該請求。

爲了解決這個問題,你可以添加到httpd.conf

PassengerResolveSymlinksInDocumentRoot on 
的[Ruby on Rails的服務器選項(