Domain setting using ruby rails - ruby-on-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.

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.

rails scope root and multiple apps

I have a working rails app accessible directly from http://0.0.0.0:3000/ . The app is also in staging and production in heroku.
Today, I want to start working on a new rails app in the same computer. How can I start working on the new unrelated app under a different path without messing up my staging/production urls ?
How can I have something like this locally and switch between the two apps
http://0.0.0.0:3000/existingApp/
http://0.0.0.0:3000/newapp/
I tried scope "/existingApp" do in my routes.rb for / and I suppose I should do that for the new app as well... but how do I specify this only for my local environment? I would like my heroku urls to stay unchanged (ie stay at the root).
I wouldn't recommend doing what you're doing, but if you're gonna do it anyway, you could try writing an engine and mounting it.
This could help get you started.
Almost any server would be able to be configured to listen to a port other than 3000. Thin, for example, can be started as:
thin -R config.ru -a 127.0.0.1 -p 8080 start
And would then listen on port 8080. Rails server can be started similarly using:
rails server -e production -p 4000
You may want to also consider starting your database using a port different than the standard one, but that is probably not necessary.

Port Redirection To Domain Issue

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.

How to specify a web address to a rails application?

I am using Ubuntu 12.04 and I have a rails application, that I would like to start on boot. Also if I start the server from console like
cd <path of the application>
rails s -p 3000
I will have to keep the console open, else the application will end as soon as I end the terminal.
Second to access the application I will have to access localhost:3000. I would rather like to have access it with a proper name like localhost/myapp or just myapp in browser.
First, is it possible? How do I do that?
PS: I already have some PHP applications running on Apache. I would not like to mess with the default 80 / 8080 port.
Edit /etc/hosts to add
127.0.0.1 myapp
Also, start with rails s -p 80 if you don't want to specify the 3000 port in the browser. This can interfere with an Apache process already listening to the 80 port.
EDIT : To make it work with Apache :
Let the Rails app on the 3000 port and enable mod proxy for Apache, in order to ProxyPass requests incoming to the myapp host.
There is several examples here : httpd.apache.org/docs/2.0/mod/mod_proxy.html
You can use pow for this. Its a zero-config Rack server for Mac OS X.
** Edit **
Prax is an alternative for Linux OS
If you don’t want to edit your hosts file you can also make use of localtest.me. Simply access your website with any subdomain like example.localtest.me:3000 or www.localtest.me:3000.

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