Ror/lighttpd - HTML files via port 80 become application/oct

Hi everybody

I am trying to get RoR to work with lighttpd.
Nearly there, but I am stuck with a strange phenomenon.

If I configure lighttpd to serve pages on say port 2000, I can get at my
testapp fine and see the “Welcome aboard” page.

However, if I configure lighttpd to use port 80, I get a download prompt
from my browser.

If I access my URI like “http://ruby.cajones.org”, I get:
‘You have chosen to open which is a: application/octet-stream from
http://ruby.cajones.org What should Firefix do with this file?’

If I access the URI as “http://ruby.cajones.org/index.html”, I get:
‘You have chosen to open index.html which is a HTML file from
http://ruby.cajones.org What should Firefox do with this file?’
If I then open it the content is the “Welcome aboard” page.

Looks like the MIME type gets screwed up if port = 80.

As a seasond admin, I spent a day trying to fix this but couldn’t find
the problem :frowning:

(There was a appearent bug in Debian/lighttpd, some perl script to wrap
the MIME types in /etc/mime.types was not executable.
To make sure I wasn’t affected by this bug I have hardcoded all the MIME
entries in the conf file. Still, it does not make any difference. And
still everything works fine if port != 80).

My lighttpd.conf in total:


server.modules = (
“mod_rewrite”,
“mod_redirect”,
“mod_access”,
“mod_fastcgi”,
“mod_compress”,
“mod_accesslog”,
)
server.document-root = “/www/TestApp/public”
server.errorlog = “/var/log/lighttpd/error.log”
server.indexfiles = ( “index.html”,
“index.htm”,
“index.php”,
“default.htm”
)
mimetype.assign = ( “.png” => “image/png”,
“.jpg” => “image/jpeg”,
“.jpeg” => “image/jpeg”,
“.html” => “text/html”,
“.txt” => “text/plain”
)

accesslog.filename = “/var/log/lighttpd/access.log”
url.access-deny = ( “~”, “.inc” )
server.port = 80
server.error-handler-404 = “/dispatch.fcgi”
server.pid-file = “/var/run/lighttpd.pid”
server.dir-listing = “enable”
server.username = “www-data”
server.groupname = “www-data”
fastcgi.server = ( “.fcgi” =>
( “localhost” =>
(
“min-procs” => 1,
“max-procs” => 5,
“socket” => “/tmp/ruby-railsapp.fastcgi”,
“bin-path” => “/www/TestApp/public/dispatch.fcgi”
)
)
)

fastcgi.debug = 1

Using this very config file and only changing the port number yields a
valid page. Using port 80 screws up the MIME type.

Any hints would be very much appreciated.

FYI. Server = Debian Sarge
Ruby = 1.8.4
Rails = 1.0.0
Lighttpd = 1.4.8
Postgres = 8.1.2

This box runs no other stuff.


Dick Visser
TERENA IT-support officer / webmaster
Singel 468D, 1017 AW, Amsterdam, The Netherlands
Phone: +31 20 5304488 Fax: +31 20 5304499
Email: [email protected] http://www.terena.nl
Live IPv4/6 webcam: http://www.terena.nl/~dick
PGP-key: http://www.terena.nl/~dick/pgp.key.asc

What happens if you
On Jan 27, 2006, at 5:40 AM, Dick Visser wrote:

Hi everybody

I am trying to get RoR to work with lighttpd.
Nearly there, but I am stuck with a strange phenomenon.

That is very strange indeed! Especially on a new box.

Have you tried using curl to see what headers are actually being
given? e.g.

curl -I -G http://localhost:3000/

Should tell you what, exactly, the difference is between port 80 and
non-port-80.

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Duane J. wrote:

Have you tried using curl to see what headers are actually being given?
e.g.

curl -I -G http://localhost:3000/

Should tell you what, exactly, the difference is between port 80 and
non-port-80.

I’m trying to get this working together with Dick. I’ve been running
webrick and lighty using script/server for months now, but getting it to
work in production mode is just a real pain.

It’s now sort of working, on port 80, but only the public/index.html
works properly. When I try to connect to localhost/people/list I get a
blank page (logged as 200). Requesting the same page using script/server
works fine.

Here’s the config file

server.port = 80
server.username = “www-data”
server.groupname = “www-data”
server.pid-file = “/var/run/lighttpd.pid”
accesslog.filename = “/var/log/lighttpd/access.log”
server.errorlog = “/var/log/lighttpd/error.log”

Default configuration file for the lighttpd web server

Start using ./script/server lighttpd

server.modules = ( “mod_rewrite”, “mod_accesslog”,
“mod_fastcgi” )
server.error-handler-404 = “/dispatch.fcgi”
server.document-root = “/www/test/public”

/www/test/public/ doesn’t change anything …

url.rewrite = ( “^/$” => “index.html”, “^([^.]+)$” =>
“$1.html” )

Change *-procs to 2 if you need to use Upload Progress or other tasks

that

need to execute a second request while the first is still pending.

fastcgi.server = ( “.fcgi” =>
( “localhost” =>
(
“min-procs” => 1,
“max-procs” => 1,
“socket” => “/tmp/fcgi.rails.socket”,
“bin-path” => “/www/test/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “development” )
)
)
)

mimetype.assign = (
“.css” => “text/css”,
“.gif” => “image/gif”,
“.htm” => “text/html”,
“.html” => “text/html”,
“.jpeg” => “image/jpeg”,
“.jpg” => “image/jpeg”,
“.js” => “text/javascript”,
“.png” => “image/png”,
“.swf” => “application/x-shockwave-flash”,
“.txt” => “text/plain”
)

Any ideas??

Jeroen

Dick-

I'm not sure exactly what your problem is but you are missing one

line from your lighttpd.conf that may be the culprit:

url.rewrite = ( “^/$” => “index.html”, “^([^.]+)$” => “$1.html” )

Hope that helps, if it doesn’t let me knwo and I will send you a
lighttpd.conf that works great on debian for me with many many rails
sites.

Cheers-
-Ezra’
On Jan 27, 2006, at 4:40 AM, Dick Visser wrote:

My lighttpd.conf in total:
server.document-root = “/www/TestApp/public”
“.txt” => “text/plain”
fastcgi.server = ( “.fcgi” =>
fastcgi.debug = 1
Ruby = 1.8.4
TERENA IT-support officer / webmaster
Singel 468D, 1017 AW, Amsterdam, The Netherlands
Phone: +31 20 5304488 Fax: +31 20 5304499
Email: [email protected] http://www.terena.nl
Live IPv4/6 webcam: http://www.terena.nl/~dick
PGP-key: http://www.terena.nl/~dick/pgp.key.asc


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]

Barry W. wrote:

I had this problem like this a few days ago. Somehow my Firefox cache
decided the address linked to an app stream (from a completly different
ip). Refreshing didn’t help. When I cleared the Firefox cache,
everything was fine.

Worth a try if you’re using Firefox.

Yep I experienced that too and switched to IE (I’m on windows). Then I
could get to the index.html by all my real app pages still didn’t work.

Right now I’m at home on a Mac and after a lighty reboot everything nows
works on Safari and FF 1.5

Pretty weird, but I’m just gonna forget it ever happened I think.

Thanks!

Jeroen

I had this problem like this a few days ago. Somehow my Firefox cache
decided the address linked to an app stream (from a completly different
ip). Refreshing didn’t help. When I cleared the Firefox cache,
everything
was fine.

Worth a try if you’re using Firefox.

Barry

On Jan 27, 2006, at 10:12 AM, Jeroen H. wrote:

given? e.g.
people/list I get a blank page (logged as 200). Requesting the same
page using script/server works fine.

Have you tried directly running lighttpd using the auto-generated
lighttpd.conf file in the RAILS_ROOT/config folder? If it works with
script/server then it should work with that script. Here’s what
script/server is doing behind the scenes, maybe you can find some
clue from it (I have nothing). This came from the rails gem lib/
commands/servers/lighttpd.rb. Note the lighttpd command second line
from last:

unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { lighttpd - version }.blank?
puts “PROBLEM: Lighttpd is not available on your system (or not in
your path)”
exit 1
end

unless defined?(FCGI)
puts “PROBLEM: Lighttpd requires that the FCGI Ruby bindings are
installed on the system”
exit 1
end

require ‘initializer’
configuration = Rails::Initializer.run(:initialize_logger).configuration

config_file = “#{RAILS_ROOT}/config/lighttpd.conf”

unless File.exist?(config_file)
require ‘fileutils’
source = File.expand_path(File.join(File.dirname(FILE),
“…”, “…”, “…”, “configs”, “lighttpd.conf”))
puts “=> #{config_file} not found, copying from #{source}”
FileUtils.cp source, config_file
end

config = IO.read(config_file)
default_port, default_ip = 3000, ‘0.0.0.0’
port = config.scan(/^\sserver.port\s=\s*(\d+)/).first rescue
default_port
ip = config.scan(/^\sserver.bind\s=\s*“([^”]+)"/).first rescue
default_ip
puts “=> Rails application started on http://#{ip || default_ip}:#
{port || default_port}”

tail_thread = nil

if ARGV.first == “-d”
puts “=> Configure in config/lighttpd.conf”
detach = true
else
puts “=> Call with -d to detach (requires absolute paths in config/
lighttpd.conf)”
puts “=> Ctrl-C to shutdown server (see config/lighttpd.conf for
options)”
detach = false

cursor = File.size(configuration.log_path)
last_checked = Time.now
tail_thread = Thread.new do
File.open(configuration.log_path, ‘r’) do |f|
loop do
f.seek cursor
if f.mtime > last_checked
last_checked = f.mtime
contents = f.read
cursor += contents.length
print contents
end
sleep 1
end
end
end
end

trap(:INT) { exit }
lighttpd #{!detach ? "-D " : ""}-f #{config_file}
tail_thread.kill if tail_thread

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Duane J. wrote:

It’s now sort of working, on port 80, but only the public/index.html
works properly. When I try to connect to localhost/people/list I get a
blank page (logged as 200). Requesting the same page using
script/server works fine.

Have you tried directly running lighttpd using the auto-generated
lighttpd.conf file in the RAILS_ROOT/config folder? If it works with
script/server then it should work with that script.

Duane,

I’ve got it working. It was some strange browser caching issue:
http://www.ruby-forum.com/topic/52917#27998

Thanks!

Jeroen

On Jan 27, 2006, at 1:41 PM, Duane J. wrote:

lib/commands/servers/lighttpd.rb. Note the lighttpd command second
puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are
unless File.exist?(config_file)
default_port
else
loop do
end
Duane J.
(canadaduane)
http://blog.inquirylabs.com/

Keep in mind that the config file generated by rails uses relative
paths to public and the dispatch.fcgi, unfortunately lighttpd1.4.9
breaks with relative paths and won’t work at all. I am working on a
patch that will expand the paths in the auto gen file to make it work
with the new lighty but its not available yet.

Cheers-

-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]