views:

150

answers:

4

I have an apache server running, with mongrels underneath running rails. The apache config file for my rails app looks like this:

<VirtualHost *:80>
  ServerName trunk.production.charanga
  ServerAlias max.trunk.production.charanga

  DocumentRoot /home/max/work/e_learning_resource/trunk/public

  RewriteEngine On

  <Proxy balancer://mongrel1>
    BalancerMember http://127.0.0.1:5010
  </Proxy>

  # Redirect all non-static requests to thin
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://mongrel1%{REQUEST_URI} [P,QSA,L]

  ProxyPass / balancer://mongrel1/
  ProxyPassReverse / balancer://mongrel1/
  ProxyPreserveHost on

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  # Custom log file locations
  ErrorLog  /home/max/work/e_learning_resource/trunk/log/error.log
  CustomLog /home/max/work/e_learning_resource/trunk/log/access.log combined

</VirtualHost>

I thought that this would let me access it from another computer with max.trunk.production.charanga, but there's another step i'm sure, that i can't figure out. At the moment, if i type my ip address into the address bar in firefox on another computer, i see the default apache server (with "It works!" etc), but i can't get to my rails apache server. Please correct me if i'm using the wrong terminology here...

thanks max

A: 

The computer attempting to access it needs to know how to resolve the DNS entry max.trunk.production.charanga to the correct IP address 192.168.1.42 (or whatever is the IP address of your server). It cannot figure this out without being told.

You can usually tell it this information by editing /etc/hosts and pointing that address to the correct IP address. Just simply having Apache recognize the name doesn't allow your other machines to know how to access it.

Alternatively, if you run a local DNS service, you can add an entry there.

Topher Fangio
Hi Topher - what you're talking about would just resolve 'max.trunk.charanga' into the ip address of my machine wouldn't it? In other words, it would be the same as them typing in the ip address of my machine. But, when i do this on another machine, i just see the default apache page, not my rails page. Do i maybe need to run my rails apache on a non-default port, and add that port to the ip? I tried that but it didn't seem to work.
Max Williams
@Max - No, the way that Apache knows how to render the page is entirely dependent upon the name that is used to access it. What you have is a named virtual host. Apache, depending on what URL was used to access the server, will render different content, thus, if you just type in the IP address, it will render the default page because it didn't know about which "site" you were asking. If, however, you assign a DNS entry (or add one in your /etc/hosts file) then when users type that in, Apache will know which site you want to render instead of the default. Google for Apache named virtual hosts.
Topher Fangio
A: 

Editing of your hosts file is a quick and easy solution.

Adding the line

192.168.1.1    trunk.production.charanga max.trunk.production.charanga

to it will tell your computer to use that ip for that domain. Depending on your browser (Firefox does caching internaly) or your OS (windows caches as well), you may need to restart your browser or flush your dns cache.

For more information about your hosts file (including where to find it on different OSes), check this wikipedia link.

Bryan McLemore
A: 

I think it just simple,

I always do like this. example . 200.100.10.1:3000/ . I access my friend web application in another city.

or

<VirtualHost>
DocumentRoot /htdoc/trunk/ <-- this is my app path. I move my rails app into xampp for exp
ServerName 200.100.10.1:3000
ServerAlias 200.100.10.1
</VirtualHost>

so I just type 200.100.10.1 to access their application if i'm not wrong. I hope it work

Kuya
Hi Kuya - like i said"At the moment, if i type my ip address into the address bar in firefox on another computer, i see the default apache server (with "It works!" etc), but i can't get to my rails apache server."
Max Williams
A: 

I found the answer: the solution is to make the required server the default server for my ip address. I did this by changing the top of the config file for the required site (/etc/apache2/sites-available/001-trunk in this case)

from this

<VirtualHost *:80>
  ServerName trunk.charanga
  ServerAlias max.trunk.charanga

  DocumentRoot /home/max/work/e_learning_resource/trunk/public
  ......etc

to

NameVirtualHost 192.168.0.234:80
<VirtualHost 192.168.0.234:80>
  ServerName trunk.charanga
  ServerAlias max.trunk.charanga

  DocumentRoot /home/max/work/e_learning_resource/trunk/public
  .....etc

where 192.168.0.234 is my network ip address.

Now, when someone else enters that ip in a browser they get the site i want them to get instead of the apache default site.

Thanks everyone for your advice!

Max Williams