Forum: Ruby on Rails rails with apache virtual hosts, mongrel

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris H. (Guest)
on 2009-01-31 05:05
(Received via mailing list)
Under windows, I am able to set up one virtual host that works with
mongrel no problem.  The issue is when I set up additional ones I
cannot get to them.  I look in the log file of the first app and it is
trying to go there.
Does anyone know how to set up multiple virtual hosts with rails?
Thomas r. K. (Guest)
on 2009-01-31 10:54
(Received via mailing list)
Hi,

This is not a rails problem but an issue for your webserver.
I can only speak for unix systems but the path is usually the same:

user sends a request to port 80, the webserver (e.g. apache) accepts
it and
decides wether to deliver a file or proxy the request to the mongrel.
Usually there are more than one mongel and they run on port 3000
upwards.

Let us know about you system details, what webserver you use.

ciao, tom

On Jan 31, 4:04 am, Me <removed_email_address@domain.invalid> wrote:
> Under windows, I am able to set up one virtual host that works with
> mongrel no problem.  The issue is when I set up additional ones I
> cannot get to them.  I look in the log file of the first app and it is
> trying to go there.
> Does anyone know how to set up multiple virtual hosts with rails?


--
Thomas R. "TomK32" Koll <> http://ananasblau.com
just a geek trying to change the world
http://github.com/TomK32
Chris H. (Guest)
on 2009-01-31 16:59
(Received via mailing list)
windows, apache 2.2.  I set the virtual hosts like the docs say but I
can
only get to one of them, the first one in the list of virtual hosts.
Conrad T. (Guest)
on 2009-01-31 17:12
(Received via mailing list)
On Sat, Jan 31, 2009 at 6:58 AM, Chris H. <removed_email_address@domain.invalid>
wrote:

>> I can only speak for unix systems but the path is usually the same:
>>
>> just a geek trying to change the world
>> http://github.com/TomK32
>>
>>
>
Hi, are you using a different ServerName for each virtual host?  Also,
did
you
correctly configure the equivalent of Unix hosts' file under Windows?

-Conrad
Chris H. (Guest)
on 2009-01-31 17:20
(Received via mailing list)
Do you need to modify the hosts file if I go to my server address? Yes
i have a different ServerName for each one.
Hassan S. (Guest)
on 2009-01-31 17:31
(Received via mailing list)
On Sat, Jan 31, 2009 at 7:20 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> Do you need to modify the hosts file if I go to my server address? Yes
> i have a different ServerName for each one.

So are you accessing your server by IP address or host name?
If it's the former you have to use a different IP for each virtual host.

Perhaps you should post the relevant parts of your conf files.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Conrad T. (Guest)
on 2009-01-31 17:32
(Received via mailing list)
On Sat, Jan 31, 2009 at 7:20 AM, Me <removed_email_address@domain.invalid> 
wrote:

> >
> > >> Usually there are more than one mongel and they run on port 3000
> is
> > you
> > correctly configure the equivalent of Unix hosts' file under Windows?
> >
> > -Conrad
>

Hi, I'm not a Windows expert but I believe that you do have to modify
the
hosts'
file to contain all the server names contained in your virtual hosts'
file.

-Conrad
Chris H. (Guest)
on 2009-01-31 17:34
(Received via mailing list)
My server is local.  IP address on my netowrk  at home.  I go to IP/??
for
my rails apps

On Sat, Jan 31, 2009 at 9:30 AM, Hassan S. <
Hassan S. (Guest)
on 2009-01-31 17:50
(Received via mailing list)
On Sat, Jan 31, 2009 at 7:33 AM, Chris H. <removed_email_address@domain.invalid>
wrote:
> My server is local.  IP address on my netowrk  at home.  I go to IP/??  for
> my rails apps

If you want to use Named Virtual Hosts, then those names need to
be resolvable, though DNS, NIS, your local hosts file -- something.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 17:51
(Received via mailing list)
OK, well like in the previous replies, the first one works no problem
it is the ones after in the file that do not work.

On Jan 31, 9:49 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 17:54
(Received via mailing list)
On Sat, Jan 31, 2009 at 7:50 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> OK, well like in the previous replies, the first one works no problem
> it is the ones after in the file that do not work.

The "first one" /what/?  Hostname? Is that the actual hostname of
your computer?  A minute ago you said you were accessing your
server by IP address. Which is it?

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 18:01
(Received via mailing list)
The first virtual host.

My sever locally is ex. 192.168.1.1

I go to 192.168.1.1/myapp1

that app  in my vitual host works

If I go to 192.168.1.1/myapp2

it says page cannot be displayed.  It is the rails error page coming
from myapp1.

On Jan 31, 9:54 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 18:09
(Received via mailing list)
On Sat, Jan 31, 2009 at 8:01 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> The first virtual host.
>
> My sever locally is ex. 192.168.1.1
>
> I go to 192.168.1.1/myapp1
>
> that app  in my vitual host works
>
> If I go to 192.168.1.1/myapp2

The above has exactly nothing to do with "virtual hosts", so I'm not
sure where your subject line comes from. If you're trying to "fix" the
above situation with virtual host directives, you're going to be badly
disappointed :-)

You need appropriate proxy settings for your *one* host.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 18:12
(Received via mailing list)
OK I was trying to avoid pasting the virtual hsots file but here it
goes:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName employeedb
DocumentRoot "F:/BACKUP/Backup/Web_apps_svn_working/employeedb/public"

RewriteEngine On

 <Directory "F:/BACKUP/Backup/Web_apps_svn_working/employeedb/public"
>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 </Directory>

 ProxyRequests Off
 ProxyPass / http://localhost:3000/
 ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost on

 </VirtualHost>


 <VirtualHost *:80>
 ServerName turindata
 DocumentRoot "F:/BACKUP/Backup/Subversion Server/httpd/deploy_apps/
Turindata/public"

 <Directory "F:/BACKUP/Backup/Subversion Server/httpd/deploy_apps/
Turindata/public" >
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 </Directory>

 ProxyRequests Off
 ProxyPass / http://localhost:3001/
 ProxyPassReverse / http://localhost:3001/
 </VirtualHost>


On Jan 31, 10:08 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 18:19
(Received via mailing list)
On Sat, Jan 31, 2009 at 8:11 AM, Me <removed_email_address@domain.invalid> 
wrote:

> ServerName employeedb

>  ServerName turindata

Might work -- if you were accessing your server /using those names/
e.g. http://employeedb/  and http://turindata/

So either do that, or dump all the virtual host stuff and fix your proxy
settings to respond to the format e.g. http://192.168.1.1/myapp1, if
that's what you want.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 18:23
(Received via mailing list)
Ok, well this is where it gets odd, like I said before I can go to:

I have my local server set up for http requests from my router.
I can go to:
http://192.168.1.1/turindata

no problem

the other app bombs

On Jan 31, 10:19 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 18:39
(Received via mailing list)
On Sat, Jan 31, 2009 at 8:22 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> Ok, well this is where it gets odd, like I said before I can go to:

It's not "odd" at all. You're seeing the first app that matches as the
default. That is NOT an indication that it's "working", even partially.

If you don't use the defined server names to access your app, the
current configuration *WILL NOT WORK*.

I suggest you first make up your mind how you want to access your
server, as two virtual hosts, or 1 host with separate apps as you're
apparently attempting now.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 18:47
(Received via mailing list)
huh, well I am doing it according to the apache docs.

the *:80 routes all traffic from port 80 and the ServerName
differentiates between the different virtual hosts.

I go to http://192.168.1.1/turindata
I should be able to go to http://192.168.1.1/employeedb

If this is not correct can you please instruct me how to make this
happen somehow?

I am not an apache guru just trying to go by the rails stuff I have
found and apache docs.



On Jan 31, 10:38 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 18:57
(Received via mailing list)
On Sat, Jan 31, 2009 at 8:46 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> huh, well I am doing it according to the apache docs.

> I go to http://192.168.1.1/turindata
> I should be able to go to http://192.168.1.1/employeedb

One more time -- the above has nothing to do with "virtual hosts".
Nothing. At. All. Let's try again.

Check one, and only one:

[ ] I want to access my apps as separate virtual hosts, as in:
    http://employeedb/
    http://turindata/

[ ] I want to access my apps on one host, in this case '192.168.1.1',
    using different paths:
     http://192.168.1.1/turindata
     http://192.168.1.1/employeedb

Those are your choices. Either is easily implemented.

Just make up your mind.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 19:01
(Received via mailing list)
IP/app
IP/app1

Not sure how to do it using mongrel on apache.  All I have seen it doing
it
with virtual hosts.  proxy to mongrel and back.

On Sat, Jan 31, 2009 at 10:56 AM, Hassan S. <
Hassan S. (Guest)
on 2009-01-31 19:11
(Received via mailing list)
On Sat, Jan 31, 2009 at 9:01 AM, Chris H. <removed_email_address@domain.invalid>
wrote:
> IP/app
> IP/app1

OK, dump all the virtual host stuff you're not using and under the
default host put something like:

    ProxyPass /app/ http://localhost:3000/
    ProxyPassReverse /app/ http://localhost:3000/

    ProxyPass /app1/ http://localhost:3001/
    ProxyPassReverse /app1/ http://localhost:3001/

Done.
--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-01-31 21:52
(Received via mailing list)
Start page works but all of my links do not work.

On Jan 31, 11:10 am, Hassan S. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-01-31 23:48
(Received via mailing list)
On Sat, Jan 31, 2009 at 11:51 AM, Me <removed_email_address@domain.invalid> 
wrote:
>
> Start page works but all of my links do not work.

Right, you'll need to set a prefix on all your routes -- I've done that
once, but don't recall the incantation at the moment. Google should
help.

Or, much easier, just use virtual hosts, like most folks do :-)

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-02-01 00:02
(Received via mailing list)
Ya, virtual hosts is what I am trying to do.  here is the one that does
not
work:  Any ideas?

<VirtualHost *:80>
    ServerName turindata
    DocumentRoot "F:/BACKUP/Backup/Subversion
Server/httpd/deploy_apps/Turindata/public"
    RewriteEngine On
    <Directory "F:/BACKUP/Backup/Subversion
Server/httpd/deploy_apps/Turindata/public" >
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>


    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001/

</VirtualHost>

On Sat, Jan 31, 2009 at 3:48 PM, Hassan S. <
Hassan S. (Guest)
on 2009-02-01 00:17
(Received via mailing list)
On Sat, Jan 31, 2009 at 2:02 PM, Chris H. <removed_email_address@domain.invalid>
wrote:
> Ya, virtual hosts is what I am trying to do.  here is the one that does not
> work:  Any ideas?

It "doesn't work" because you haven't, as far as I can tell, tried it.

http://turindata/  is NOT THE SAME AS http://192.168.1.1/turindata

If you don't request the virtual server you've defined, what makes
you think that it will magically respond to some entirely different and
unrelated request URL?

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-02-01 00:21
(Received via mailing list)
Well the virtual host above works:

<VirtualHost *:80>
ServerName employees
DocumentRoot "F:/BACKUP/Backup/Web_apps_svn_working/employeedb/public"

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

</VirtualHost>

I go to http://IP/employees

and I get the index page which is what it should do.

The other one says:
Routing Error

No route matches "/turindata" with {:method=>:get}




On Sat, Jan 31, 2009 at 4:16 PM, Hassan S. <
Hassan S. (Guest)
on 2009-02-01 00:39
(Received via mailing list)
On Sat, Jan 31, 2009 at 2:21 PM, Chris H. <removed_email_address@domain.invalid>
wrote:
> Well the virtual host above works:

No. It. Doesn't. It ONLY APPEARS TO.  Do you understand the
concept of "default"?

> I go to http://IP/employees

As long as you insist on trying to configure "virtual hosts" and NOT
USING THE VIRTUAL HOST NAME, you are wasting your time.

Last try:

http://turindata/  is NOT THE SAME AS http://192.168.1.1/turindata

NOT. THE. SAME.

If you can't understand that, I give up.

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Chris H. (Guest)
on 2009-02-01 00:43
(Received via mailing list)
Do you mean this statement?

NameVirtualHost *:80

I have that there.

The apache docs say that statement routes all traffic on port 80 to the
virtual hosts.

If thee is something I am missing please let me know.

I have this:

NameVirtualHost *:80
ProxyRequests Off

<VirtualHost *:80>
ServerName employees
DocumentRoot "F:/BACKUP/Backup/Web_apps_svn_working/employeedb/public"

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

</VirtualHost>

<VirtualHost *:80>
    ServerName turindata
    DocumentRoot "F:/BACKUP/Backup/Subversion
Server/httpd/deploy_apps/Turindata/public"
    RewriteEngine On

    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001/

</VirtualHost>


I go to this on each one:

http://192.168.1.1/employees -> works
http://192.168.1.1/turindata -> does not work


On Sat, Jan 31, 2009 at 4:38 PM, Hassan S. <
Jeff B. (Guest)
on 2009-02-06 00:51
(Received via mailing list)
Hi Chris,

In case you haven't already solved this problem of running multiple
rails apps under the same domain via apache, ... try mod'ing your app-
specific proxypass/reverse directives like:

...
  ProxyPass /employees http://localhost:3000/employees
  ProxyPassReverse /employees http://localhost:3000/employees
...
  ProxyPass /turindata http://localhost:3001/turindata
  ProxyPassReverse /turindata http://localhost:3001/turindata
...

Reload or restart apache, and you should then be able to hit those two
apps as intended:

http://192.168.1.1/employees
http://192.168.1.1/turindata

The only other issue you might have, depending on what those two apps
do and how they're implemented, is dealing with in-app static file
ref's not being found/returned via apache.

For example say the employees app had the following img ref in one of
the view templates: ... <img src="/images/some-img.png" ....  If you
were hitting that app via localhost, your browser would fetch that img
from http://localhost:3000/images/some-img.png.  Under your apache
setup, that file would be fetched from
http://192.168.1.1/images/some-img.png.
So, you'll likely need to setup your apps / apache / sys in a way that
apache can find/return those static public files ref'd by each app
proxy'd under that one domain (since you're wanting to serve those
apps under the same domain).

There are a number of ways to deal with this, both via apache
directives and rails app/config tweaks, but one fairly easy agnostic
(?) kludge is to just use symbolic links:

(following is unix/linux example, but should be translatable to
windows)

### create sym link to app's pub dir under that pub dir:
$ cd /path-to-employees-app/public
$ ln -s . ./employeespub

### create sym link to app's pub dir under main virt host domain
documentroot:
$ cd /path-to-domain-documentroot/htdocs
$ ln -s /path-to-employees-app/public ./employeespub

### then make sure your app's static file refs point to that new sym-
link:
... <img src="/employeespub/images/some-img.png" ...

### done.

After that, all of your app-specific static file refs should work
under both localhost (ie
http://localhost:3000/employeespub/images/some-img.png)
and apache (ie http://192.168.1.1/employeespub/images/some-img.png).

Jeff
This topic is locked and can not be replied to.