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.
Related
i've got some problems with my ruby on rails server.
It is running under localhost:3333 in my debian vm under a windows8 host.
I've installed apache2 and passengermodul for apache to get ruby. And then I've installed rails.
Now I need a subdomain wich calls the ruby on rails server.
for example admin.localhost:3333
Is something like that possible? And when how can I configurate it?
You can use the lvh.me domain. That domain has a DNS entry that will redirect to localhost. This also works for subdomains, so you can visit admin.lvh.me:3000 and it will redirect to localhost:3000 while still having the subdomain available in the Rails request.
The advantage is that you don't have to edit your localhost file.
Add custom hosts with subdomains to the hosts file, follow these steps
In your terminal, open hosts file
cd /etc
sudo nano hosts
Add the host as mentioned in the following lines to the hosts file, you can add as many as you want
127.0.0.1 admin.localhost
127.0.0.1 subdomain.localhost
Save the file, CTRL + X then press Y
Done.
To run with a custom port, specify the port number while starting the server,
rails s -p 3333
Now you can run your application with, admin.localhost:3333
Hope this helps!
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.
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.
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.
I am trying to learn Ruby on Rails, I have followed the instructions from this page to get rails installed on my PC.
I am also trying to follow this webcast to try and learn the language and framework. Everything is working so far, apart from the fact that I cannot access
http://localhost:3000
http://0.0.0.0:3000
http://127.0.0.1:3000, or
http://<actual IP address>:3000
locally. If I try the from another PC on my network then it works great. I have tried in Chrome, Firefox and IE7 but none work.
Has anyone else had this problem?
EDIT: Typical!! It's started working now. I have no idea why, I am typing the exact same address in to the address bar and it now works. But only if I use http://127.0.0.1:3000, localhost doesn't work. I do run IIS ASP.NET/ASP websites on this machine, and they work fine with localhost.
EDIT 2: If I trying pinging localhost it actually says
Reply from ::1: time<1ms
0.0.0.0 yields...
PING: transmit failed, error code 1214
only 127.0.0.1 seems to work. I did have IPv6 turned on, so I've disabled that and will try again tomorrow to see if a reboot helps.
I had this issue as well with Vagrant. The secret is to run
bin/rails server -b 0.0.0.0
What 0.0.0.0 means is to listen to all interfaces, not just on localhost. The alternative is to SSH into the vagrant machine with a SOCKS proxy.
ssh -C -D 8080 vagrant#localhost
Open up your Internet explorer proxy settings and set the SOCKS v5 proxy to port 8080.
In order to access http://localhost:3000 you need to run the local Rails server in a terminal window:
$ rails server
This is described in this section of the Rails Tutorial book.
Note: I am the presenter of the screencasts in question.
Can you telnet to the port? Try:
telnet localhost 3000
That should tell you if the ports unavailable at the TCP level, or whether something's going on at the HTTP level.
Ping might not work if ICMP is disabled, which could be completely unrelated to your issue.
Also, try looking in your hosts file for any redirections:
c:\Windows\System32\drivers\etc\hosts
One way is to do the simple
rails s
Another (more specifically) is
rails start localhost 0.0.0.0
or
rails start 0.0.0.0
another way is
rails s 0.0.0.0
all of these works
I had an epic issue with my System Path (Environmental Variable) not being set properly.
Simple copy paste job, unplugged the 1 week stalled Ruby installation.
Control Panel > System > Advanced tab > Environment Variables > System variables > Path... Edit...
Make sure it contains these paths (among others)...
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
I had your same identical problem. You have simply to run
$ rails server
from inside the folder of your application, not outside...so, if you have your application in
C:\Sites\myapp\blog
and blog is the folder where live your app, the command has to be prompted from here. Launching it from myapp folder won't work.
Are you possibly using a proxy but haven't listed localhost as proxy exception?
Have you tried disabling your firewall? They can cause pesky problems at times.