Port Redirection To Domain Issue - ruby-on-rails

I am using Cent OS 5.8 with kloxo.
I have a ruby application. When i start the application , by default it starts at port nos 3000. So to access dat i need to put domain.com:3000 .
This doesn't look good , so I decided to run mongrel at port nos 80.
now i am able to access domain.com
But now i want that the application shall run in a sub domain and there should be a different website running in my main domain.
I tried putting code in httpd.conf and it didn't work.
Can any one help me on this.
Thank You

You can use nginx as a proxy to accomplish this. You can then run your apps on ports 3000, 3001 and 3002 (for example) and let nginx route the traffic based on the hostname requested. But I recommend you looking into Phusion Passenger for production environments because it enables you to run applications like you're used to in an Apache or nginx environment. According to Phusion, it also outperforms Mongrel, but your mileage may vary of course.

Related

What is localhost:8000 as used in Codecademy (for AngularJS and Ruby on Rails tutorials)?

I want to know what is this: localhost:8000, found in Codecademy tutorials for AngularJS and Ruby on Rails. I even installed Apache 2, but to work with it I need to dial: http://localhost/. While working on some html files, I often come across Firefox's Inspect Element where a section is to mention localhost and its number like this: localhost:8000. I want to know what's this and can I use it to access my host from my android device or some other PC as we do access Codecademy's localhost to learn AngularJS and Ruby on Rails. Pls help. Thanks in advance. :-)
Localhost is the loopback-address of your pc. The IP-address behind it is 127.0.0.1. With localhost, it is possible to simulate a web-server environment and it is mostly used to simulate running web-applications as if they are running on a webserver. :8000 stands for the port-number on which the browser connects to the server. This is because the application runs (in this case) on port 8000 of the server. So it is not enough to just install Apache 2 and surf to http://localhost/ you have to configure Apache so that it runs your web-application on the desired port. The port-number itself has no special meaning. The different ports are just a part of the url so the browser knows on which port it has to connect. Some protocols use default ports. (e.g. HTTP will always connect to port 80, unless your specify another port in your webbrowser)
I'm sure a lot of people can explain it much better, but here is a begin.
More info about running ruby on rails on an Apache webserver:
How can i run a ruby on rails project on apache server?
How to setup Ruby on Rails Hosting using Apache, from Development to Production
EDIT: Technically, the whole 127.0.0.0/8 address block is reserved for loopback purposes. The default one, configurged in hosts.txt is 127.0.0.1 and the most famous.

Domain setting using ruby rails

I am planning to have a web application.
To do so, I studied about ruby and ruby on rails. I am using linux server from amazon clouding system.
I bought a domain from godday, and I put the IP address on DNS setting. When I run 'rails s' command, I can connect to the wep page through port 3000 in such a way that domain.com:3000. However, I cannot directly connect to domain.com. How can I my domain works without port 3000?
And Do I have to run 'rails s' every time to make the wep page work? Actually I tried to use 'rails s &' to make it run in background. But it fails. How can I make the server run even though I am not connected to the linux server?
Thank you!
usually you use rails s just in development. there are quite a few ruby web servers you can choose from for your production environment: puma, passenger or unicorn to name a few.
of course all of them have their own tutorials how to set them up. for starters, i'd go with with passenger because it's integrated with nginx and apache and easily set up.
You need to specify a port, if you don't see the port it can be either 80 (http) or 443 (https).
rails server -p 80
On linux you have to be root to bind to port less than 1000, so just append sudo in front.

etc/hosts with port number (fix for foreman)

I am using Foreman specifing port 3000. How can I access my application by writting myapp.local in the browser instead of typing 0.0.0.0:3000?
I have added:
0.0.0.0 myapp.local
But when doing myapp.local it defaults to the default localhost for Apache, not the Rails app.
Short answer: You can't.
The host table is meant to map hostnames to IP addresses (Wiki). Ports come in at a different point.
However, you can specify the port Foreman should run on:
-p, --port
Specify which port to use as the base for this application. Should be a multiple of 1000.
I don't know the Foreman but as you connect to it with your browser than I assume it talks via HTTP. If so you can use proxy settings to point to that host:port. Try FoxyProxy. It's more like a workaround rather than a real solution but it should work (as far as it's not HTTPS)
If you're using Linux than another way is to use LD_PRELOAD to overwrite connect glibc function. It's quite low level hack but it's not so complicated.
Another way in Linux would be to make netfilter rule (iptables) to NAT the connection. It's not nice either as you'll need root level change to achieve simple thing.

Deploy Ruby on Rails - Development Environment

I'm developing an small application on RoR and OSX 10.6.4 workstation, and I'm looking for guidance on two things: -
How to share my application locally with others so others in my team can get access to my local webserver (Mongrel?) to view/play with my system before I release it into production. From my default installation I can play with it both others can't seem to access it - not even from say http://:3000, which works from local - so I'm a bit confused.
Advice on how best to deploy it onto a production webserver assuming I deploy onto Linux. What webserver should I use and are there instructions?
Thanks in advance. Networking and webservers are NOT a strong suite :-)
Cheers
B
The development Mongrel is by default only accessible through localhost. In order to be visible from the outside you need to ask it to bind to your external IP address. Assuming your IP address is 10.0.0.5, you need to do this:
script/server -b 10.0.0.5
For deployment on Linux, the easiest way is perhaps using Passenger, and either Apache or nginx for a web server, whichever you're most comfortable with (if you have no preference, go with Apache). Documentation can be found here.
Why can't others access it via http://your.ip:3000/? ./script/server mongrel listens on 0.0.0.0 by default. 0.0.0.0 stands for listening on every interface in Linux.

Serving web application without Lighttpd/Apache

As Rails applications default run on port 3000, would it be possible to start the application on port 80? Is it really required to have a fastcgi/mod_proxy enabled web server in front? My users won't be more than three at a time. If so, how would I be able to do so?
Thanks!
WARNING: This is not a general purpose description of how to set up a Ruby on Rails production environment. If you want to host a public Rails website, I highly recommend using Apache with Passenger, which is very easy to install and maintain.
From your description, it sounds like you are working with some kind of internal application to be used within your office or similar. For this particular purpose, hosting the application via Webrick (the built-in web server in Rails) might be a sufficient solution. To do this, start the server with a -p command line argument: ruby script/server -p 80
This obviously requires port 80 to be available (not bound by some other web server). Also, on most operating systems, you will need root privileges to bind to port 80. The security implications of running a web site as root are serious, so you really only want to do this if you know what you are doing, and are absolutely sure that the server is completely shielded from the Internet.
If there isn't some specific reason you're trying to run with mongrel, I would recommend using Phusion Passenger as it is significantly easier to configure and support than mod_proxy+mongrel.
mongrel - http://github.com/fauna/mongrel
thin - http://code.macournoyer.com/thin/

Resources