View previous topic :: View next topic |
Author |
Message |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Thu Mar 03, 2005 8:28 pm Post subject: FastCGI files just appearing as text |
|
|
Hi,
I'm trying to use Ruby on Rails with FastCGI (to make it errr... faster). I have installed mod_fastcgi, apache, rails, and everything else I "should" need. I am using "AddHandler fastcgi-script .fcgi" and "Options +FollowSymLinks +ExecCGI". Yet still when I go to the site (it is a local VHost), the file just appears as plain text. I'm no Apache whiz, so I'm guessing I've left out some directive somewhere.
Any help would be appreciated.
Thanks,
Turnip |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Sat Mar 12, 2005 7:22 pm Post subject: |
|
|
My modified /etc/apache2/conf/commonapache2.conf
Code: |
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi .fpl
FastCgiIpcDir /tmp/fcgi_ipc/
</IfModule>
|
And in /etc/apache2/conf/apache2.conf
Code: | LoadModule fastcgi_module /usr/lib/apache2-extramodules/mod_fastcgi.so |
[edit] Removed FastCgiServer directive.
Last edited by Pythonhead on Thu Mar 24, 2005 6:49 pm; edited 1 time in total |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat Mar 12, 2005 8:40 pm Post subject: |
|
|
Aha, thanks a lot! I realised along the way that I didn't have "-D FASTCGI" in the apache config. It's now _working_, but not properly. The page takes ages to load, when it does it's incomplete, I have lots of stuff like this in the log file:
[Sat Mar 12 20:34:03 2005] [error] [client 127.0.0.1] FastCGI: comm with (dynamic) server "/home/turnip/test/public/stylesheets/more.css" aborted: (first read) idle timeout (30 sec), referer: http://test/
[Sat Mar 12 20:34:03 2005] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/home/turnip/test/public/stylesheets/more.css", referer: http://test/
Any ideas?
Thanks a lot,
Turnip |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Sat Mar 12, 2005 9:23 pm Post subject: |
|
|
How are you linking to the stylesheet in your .rhtml?
Are you using something like:
Code: | <%= stylesheet_link_tag('mystyles') %> |
I noticed fastcgi is much pickier about accessing anything in /public |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat Mar 12, 2005 9:44 pm Post subject: |
|
|
No, the stylesheet is called using a plain old <link> element with an absolute path.
However, I'm testing this with Hieraki (http://dev.hieraki.org/), which defaults to FCGI anyway, so it's unlikely to be a problem with the code. I tried doing it with that tag anyway, but it made no difference.
FWIW, I'm also getting the same sort of error on public/500.html |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Sat Mar 12, 2005 9:58 pm Post subject: |
|
|
Does this directory exist and is it owned by apache?
/tmp/fcgi_ipc/
I have had problems when switching between dispatchers (mod_ruby->fcgi) when there were extra /tmp/ruby_sess* files laying around. Try deleting those after shutting down apache.
Also, even if you shut down apache you may still have fcgi processes running you might want to kill before restarting apache:
Code: | ps aux|grep dispatch |
Yesterday I had a similar problem to yours. fastcgi was trying to execute any file in /public (.css, images etc).
I don't know why its working today, but it may be because I removed the fcgi startup line from above:
Code: | FastCgiServer /home/rob/ScriptTest/public/dispatch.fcgi |
|
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat Mar 12, 2005 10:40 pm Post subject: |
|
|
I've done all that, but it still doesn't work  |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Sat Mar 12, 2005 11:00 pm Post subject: |
|
|
Just for kicks how about uping the timeout to see if it finally succeeds:
Add this:
Code: | FastCgiConfig -idle-timeout 120 |
To this section:
Code: | <IfModule mod_fastcgi.c>
... |
|
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sun Mar 13, 2005 12:16 am Post subject: |
|
|
Nope, it only appears after the timeout -- broken. |
|
Back to top |
|
 |
Micand n00b

Joined: 16 Oct 2003 Posts: 23 Location: Calgary, AB
|
Posted: Thu Mar 24, 2005 12:32 pm Post subject: |
|
|
I'm experiencing the same issue. Please be gentle, for I am a Rails noobie working his way through Four Days on Rails. The basic ToDo application listed in "Day 1" worked fine when running as a CGI. After switching to FastCGI by changing "RewriteRule ^(.*)$ dispatch.cgi [QSA,L]" in public/.htaccess to "RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]", the app would error out in the browser with "Application error: Rails application failed to start properly". Apache's error log contained the same error message that Turnip received:
Code: | [Thu Mar 24 05:17:19 2005] [error] [client 127.0.0.1] FastCGI: comm with (dynamic) server "/var/www/todo/public/dispatch.fcgi" aborted: (first read) idle timeout (30 sec)
[Thu Mar 24 05:17:19 2005] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/var/www/todo/public/dispatch.fcgi" |
I'm running Apache 2.0.53, mod_fastcgi-2.4.2-r1, fcgi-2.4.0, and ruby-fcgi-0.8.5-r1. Any assistance will be much appreciated.
Thanks,
Jeff |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Thu Mar 24, 2005 4:24 pm Post subject: |
|
|
Did you also try upping the timeout value? Some people suggest 240 because of slow startup times.
Do you get any error message when you run this as apache?
Code: | sudo -u apache /var/www/todo/public/dispatch.fcgi |
You have this in your .htaccess?
Code: | AddHandler fastcgi-script .fcgi |
EDIT What version of rails are you using?
I found a bug in dispatch.fcgi 0.11.0 that could be your problem. If you try running dispatch.fcgi from the shell and it complains about RAILS_ROOT, you can try this patch (I'll add it to portage a.s.a.p):
Code: | --- public/dispatch.fcgi
+++ public/dispatch.fcgi
@@ -1,6 +1,5 @@
#!/usr/bin/ruby18
-FASTCGI_CRASH_LOG_PATH = "#{RAILS_ROOT}/log/fastcgi.crash.log"
def dispatcher_error(e, msg = "")
error_message = "[#{Time.now}] Dispatcher failed to catch: #{e} (#{e.class})\n #{e.backtrace.join("\n ")}\n#{msg}"
@@ -14,6 +13,8 @@
require 'dispatcher'
require 'fcgi'
+ FASTCGI_CRASH_LOG_PATH = "#{RAILS_ROOT}/log/fastcgi.crash.log"
+
FCGI.each_cgi do |cgi|
begin
Dispatcher.dispatch(cgi) |
Last edited by Pythonhead on Thu Mar 24, 2005 11:28 pm; edited 1 time in total |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Thu Mar 24, 2005 7:11 pm Post subject: |
|
|
Turnip, looking again at your message, its making me think fcgi is trying to execute every file type in /public.
Heres my .htaccess, using non-vhost in case some of the ReWrite{rules,cond}'s help:
Code: |
RewriteBase /script/
AddHandler fastcgi-script .fcgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi?$1 [QSA,L]
ErrorDocument 500 /500.html
|
|
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Thu Mar 24, 2005 10:33 pm Post subject: |
|
|
This is the .htaccess I'm using, which is th same:
Code: | # General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
# Redirect all requests not available on the filesystem to Rails
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]
# In case Rails experiences terminal errors
ErrorDocument 500 /500.html |
I don't think it's a problem with Apache -- I made a test app (instead of using Hieraki, which is what I'm having the problem with), and FastCGI worked fine. I'm not working with Hieraki at the moment, but if I find a solution sometime then I'll post back here. |
|
Back to top |
|
 |
Micand n00b

Joined: 16 Oct 2003 Posts: 23 Location: Calgary, AB
|
Posted: Fri Mar 25, 2005 12:31 am Post subject: |
|
|
Pythonhead wrote: |
EDIT What version of rails are you using?
I found a bug in dispatch.fcgi 0.11.0 that could be your problem. If you try running dispatch.fcgi from the shell and it complains about RAILS_ROOT, you can try this patch (I'll add it to portage a.s.a.p):
Code: | --- public/dispatch.fcgi
+++ public/dispatch.fcgi
@@ -1,6 +1,5 @@
#!/usr/bin/ruby18
-FASTCGI_CRASH_LOG_PATH = "#{RAILS_ROOT}/log/fastcgi.crash.log"
def dispatcher_error(e, msg = "")
error_message = "[#{Time.now}] Dispatcher failed to catch: #{e} (#{e.class})\n #{e.backtrace.join("\n ")}\n#{msg}"
@@ -14,6 +13,8 @@
require 'dispatcher'
require 'fcgi'
+ FASTCGI_CRASH_LOG_PATH = "#{RAILS_ROOT}/log/fastcgi.crash.log"
+
FCGI.each_cgi do |cgi|
begin
Dispatcher.dispatch(cgi) |
|
Aha, that fixed it. Thanks for the prompt reply. I am indeed running Rails 0.11.0, and I had the proper AddHandler line in my .htaccess. Upping the timeout value to 240 did nothing except lengthen the time it took for the script to error out to 240 seconds. Running "sudo -u apache /var/www/todo/public/dispatch.fcgi" produced the error message relating to RAILS_ROOT that you mentioned. However, after applying your patch and restarting Apache, everything began working. Thanks again! |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Fri Mar 25, 2005 4:17 am Post subject: |
|
|
Ok, great. I added the patch to 0.11.0-r1, thanks. |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat Mar 26, 2005 2:45 pm Post subject: |
|
|
I'm pretty sure my problem is not with Ruby, FastCGI, Apache or Rails, but with Hieraki. I created a test rails app just to see if it would work, and that runs fine under FastCGI, so I think the culprit is Hieraki. Incidentally, I don't think Hieraki has been updated for Rails 0.11.0 yet, but I'll keep that in mind for when it gets updated.
BTW, is it better to be taking Ruby stuff like Rails and friends from RubyGems or from Portage? Currently I'm using RubyGems because that's what it said to do on the Rails website. |
|
Back to top |
|
 |
Pythonhead Developer


Joined: 16 Dec 2002 Posts: 1801 Location: Redondo Beach, Republic of Calif.
|
Posted: Sat Mar 26, 2005 4:19 pm Post subject: |
|
|
Turnip wrote: |
BTW, is it better to be taking Ruby stuff like Rails and friends from RubyGems or from Portage? Currently I'm using RubyGems because that's what it said to do on the Rails website. |
Using the ebuilds actually installs a gem so theres no difference, except you get patches like the one above for fastcgi ahead of everyone else, which upstream says will go in 0.11.1.
Also I added a 'fastcgi' USE flag that pulls in a patch for dev-ruby/ruby-fastcgi that patches a nasty memory leak. So, I think Gentoo is now ahead of everyone using plain gems, as of 0.11.0 anyways.
I noticed a new Gentoo page on their wiki yesterday, which I edited at the bottom with this info:
http://wiki.rubyonrails.com/rails/show/HowtoInstallOnGentooWithApache |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat Mar 26, 2005 4:33 pm Post subject: |
|
|
Ok. I might try starting over with my installations and use Portage, then see if that makes a difference. |
|
Back to top |
|
 |
destiney n00b

Joined: 21 Dec 2003 Posts: 39
|
Posted: Sat May 28, 2005 3:01 am Post subject: |
|
|
I followed this HowTo:
http://wiki.rubyonrails.com/rails/show/HowtoInstallOnGentooWithApache
Everything installed, but now when I go to my rails app, the dispatch.fcgi appears as text.
My vhost looks like this:
Listen 10.0.0.2:8000
<VirtualHost 10.0.0.2:8000>
ServerName rails
DocumentRoot /var/www/localhost/htdocs/ruby/public
ErrorLog /var/www/localhost/htdocs/ruby/ruby.log
<Directory /var/www/localhost/htdocs/ruby/public>
Options ExecCGI FollowSymLinks
AddHandler cgi-script .cgi
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have this in /etc/conf.d/apache2 :
APACHE2_OPTS="-D FASTCGI -D RUBY -D PHP5 -D PYTHON -D PERL"
Apache isn't producing any errors in the logs, and I've stopped it and restarted it numerous times.
Tried changing the line above to AddHandler cgi-script .cgi .fcgi, but that didn't help.
Any ideas? |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat May 28, 2005 7:38 am Post subject: |
|
|
You need AddHandler fcgi-script .fcgi I think (and it always helps to say what the problem is).
I was actually fiddling with Rails last night too... I uninstalled all my gems, and then installed the packages from portage (which in turn re-installed some gems). I can use FastCGI fine, but it doesn't work with Hieraki, so I guess that must be the fault of the application. |
|
Back to top |
|
 |
destiney n00b

Joined: 21 Dec 2003 Posts: 39
|
Posted: Sat May 28, 2005 2:12 pm Post subject: |
|
|
Turnip wrote: | and it always helps to say what the problem is |
I said "when I go to my rails app, the dispatch.fcgi appears as text". Helps if you read the post you're about to reply to.
AddHandler fastcgi-script .fcgi already appears in the /var/www/localhost/htdocs/ruby/public/.htaccess. |
|
Back to top |
|
 |
Turnip n00b

Joined: 09 Feb 2005 Posts: 60 Location: Reading, UK
|
Posted: Sat May 28, 2005 2:25 pm Post subject: |
|
|
I'm sorry, I don't know how I missed that.
With regard to the problem, I can only show you my /etc/apache2/conf/modules.d/20_mod_fastcgi.conf in the hope it might be useful...
Code: | <IfDefine FASTCGI>
<IfModule !mod_fastcgi.c>
LoadModule fastcgi_module /usr/lib/apache2-extramodules/mod_fastcgi.so
</IfModule>
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcg .fcgi. fpl
FastCgiIpcDir /tmp/fcgi_ipc/
</IfModule>
</IfDefine> |
Other than that I don't know. It might be that the .htaccess file isn't allowed to do AddHandler -- there's no harm trying it out in one of the server configs. |
|
Back to top |
|
 |
destiney n00b

Joined: 21 Dec 2003 Posts: 39
|
Posted: Sat May 28, 2005 7:52 pm Post subject: |
|
|
After looking at httpd.conf I figured the problem out. The Include path for the modules.d directory was wrong. So I copied 20_mod_fastcgi.conf from /etc/apache2/conf/modules.d to /etc/apache2/modules.d.
Then I edited it to fix the broken module path:
#LoadModule fastcgi_module extramodules/mod_fastcgi.so
LoadModule fastcgi_module /usr/lib/apache2-extramodules/mod_fastcgi.so
I dunno why my apache2 install has two module.d directories. But it's all working now. |
|
Back to top |
|
 |
navjeet n00b

Joined: 09 Apr 2005 Posts: 6
|
Posted: Fri Jun 24, 2005 3:28 pm Post subject: |
|
|
You still have dispatch.cgi rather than dispatch.fcgi in
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]
--Navjeet
Turnip wrote: | This is the .htaccess I'm using, which is th same:
Code: | # General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
# Redirect all requests not available on the filesystem to Rails
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]
# In case Rails experiences terminal errors
ErrorDocument 500 /500.html |
I don't think it's a problem with Apache -- I made a test app (instead of using Hieraki, which is what I'm having the problem with), and FastCGI worked fine. I'm not working with Hieraki at the moment, but if I find a solution sometime then I'll post back here. |
|
|
Back to top |
|
 |
|