LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2008, 07:20 AM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
Apache URLs with RubyOnRails


I've set up Ruby on Rails on my CentOS 5 machine. I am using Apache and I added a few lines to the httpd.conf file, including:
Quote:
DocumentRoot "/var/www"
<Directory "/var/www">
AllowOverride All
</Directory>

LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so
<IfModule mod_fcgid.c>
SocketPath /tmp/fcgid_sock/
AddHandler fcgid-script .fcgi
</IfModule>

<VirtualHost *:80>
SetEnv RAILS_ENV development
ServerName localhost
DocumentRoot /var/www/rails/jovianvoid/public/
ErrorLog /var/www/rails/jovianvoid/log/apache.log

<Directory /var/www/rails/jovianvoid/public/>
Options ExecCGI FollowSymLinks
AddHandler fcgid-script .fcgi
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
My Rails app was created in /var/www/rails/ using the command rails jovianvoid as local user.

Starting apache with the command service httpd start works fine and browsing to http://localhost gives me the usual "You're riding on rails" page. But if I create a controller (ruby script/generate controller hello index) and try to browse to http://localhost/hello it gives me "404 Not Found".

However, if I instead start ruby script/server and browse to http://localhost:3000/hello I get the correct message: "Find me in app/views/hello/index.html.erb"

So something is wrong with my Apache setup, but what?

Please help.
 
Old 06-08-2008, 08:56 AM   #2
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
I don't know but maybe we can work it out.

First off I assume that you know what the 3000 is - the port number.

I think that the easiest solution is to put in an apache rewrite rule. I haven't played with these but I think you need to add something like this to your apache config file:

Code:
RewriteEngine On
RewriteRule ^/hello(.*) http://localhost:3000/hello$1
For details of rewrite rules see:
http://httpd.apache.org/docs/1.3/mod...ml#RewriteRule

Regards, Tischbein.
 
Old 06-08-2008, 09:13 AM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by Tischbein View Post
I don't know but maybe we can work it out.

First off I assume that you know what the 3000 is - the port number.

I think that the easiest solution is to put in an apache rewrite rule. I haven't played with these but I think you need to add something like this to your apache config file:

Code:
RewriteEngine On
RewriteRule ^/hello(.*) http://localhost:3000/hello$1
For details of rewrite rules see:
http://httpd.apache.org/docs/1.3/mod...ml#RewriteRule

Regards, Tischbein.
Yeah, Apache runs at standard port 80 while the Ruby webserver (did they change that from Webrick to Mongrel?) runs at port 3000. So that's why localhost:3000 works, but localhost:80 doesn't: my apache conf isn't working. Apache doesn't like these http://<host>/<controller>/<action> kinda URLs.
 
Old 06-08-2008, 09:36 AM   #4
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
SOLVED:

It seems that the .htaccess-file inside public/ was missing (don't know why). The guides on the net refers to it and tells you to change some lines but in my installation there was no such file. Googling for one and using it solved the problem and Apache will now handle the URLs correctly.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to manipulate apache URLs to shorten it? linuxfia Linux - General 1 05-17-2008 01:30 AM
Apache URLS riluve Linux - Software 7 08-30-2007 06:51 AM
case sensitive URLs with Apache ddaas Linux - Networking 2 08-11-2006 06:32 PM
Apache: prevent logging certain URLs ? michaelsanford Linux - Software 1 07-22-2005 07:48 PM
apache and urls ferretmanus Linux - Newbie 1 09-16-2003 01:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration