I want to map:
www.example.com
in my host file, how can I start 'rails server' so it uses this domain?
Edit the hosts file (instructions for OSX Snow Leopard)
sudo nano /etc/hosts
Add a line 127.0.0.1 www.example.com
Refresh DNS settings with sudo dscacheutil -flushcache
Start rails on the correct port
rails server will now work on http://www.example.com:3000/. To get rid of :3000, start Rails with: sudo rails server --port=80 (or rvmsudo if you are using RVM)
For production use, you might want to see Kevins answer.
I'd recommend setting up Passenger on either Nginx or Apache to do this. Doing a quick search on your operating system should come up with a tutorial on how to set everything up correctly.
Related
I have recently created an Amazon AMI(linux) instance on an EC2.
after doing all the yum stuff, when I do
rails server, the cmd shows no errors at all, but when i try to access http:public_ip:3000 through Firefox I get "Unable to connect"
I have already installed Ruby, NodeJs, Rails, and rvm.
I have asked on IRC and have tried rails s -b http://public_ip:3000
with
/home/ec2-user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/socket.rb:205:in >`bind': Cannot assign requested address - bind(2) for 52.48.217.79:3000 >(Errno::EADDRNOTAVAIL)
in return.
I've also tried ssh to the elastic IP, and when I do rails s -b http://public_ip:3000 I get:
[2016-01-17 01:43:23] INFO ruby 2.3.0 (2015-12-25) [x86_64-linux]
Exiting
/home/ec2-user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/socket.rb:231:in >`getaddrinfo': getaddrinfo: Name or service not known (SocketError)
this is all just to make sure that rails was installed well and running(I want to see the default rails page). Can anyone help?
You want to bind to 0.0.0.0.
Rails used to do this for you by default, but starting with 4.2 it only binds to localhost by default, so the command will be rails s -b 0.0.0.0.
You'll also need to make sure you have a rule set up allowing TCP traffic to port 3000 in your EC2 security group
Am sorry for the noobness for this,
I am developing a ruby on rails application on my ubuntu 14.04.
As for development, i'm starting my application using ruby script/server.
Ruby -v 1.8.7
Rails -v 2.3.14
MySql
Now my question is how to deploy this on production?
Am planning to use Ubuntu 14.04 Server as well.
I read about the Phusion Passenger but I did not understand what is that for.
I was hoping to make the ubuntu server as a localhost. So that if I point to the browser like myrailsapp, my application will be available (Normally I will use script/server). Do I have to use the script/server command everytime the server will restart?
Please tell me if im on the right track.
------------ I follow a tutorial --------------
I follow a tutorial like this one but I can't figure out how to make a virtual host working I created a virtual host like this:
/etc/hosts
0.0.0.0 example.com
/opt/nginx/conf/nginx.conf
server {
listen 80;
server_name example.com;
passenger_enabled on;
location / {
root /opt/nginx/html/ror/blog/public;
}
}
On my browser i get 403 Forbidden And do i have to start my rails app like script/server?
Try following
http://www.codesapling.com/blog/2014/04/12/set-up-guide-for-rails-server-on-ubuntu/
or
http://codebeerstartups.com/2012/10/complete-guide-to-setup-a-rails-server/
PS : May be the links outdated but help you getting started.
No you dont need to run script/server every time.
set-up your Rails-App in the server, install rails version with the command
sudo gem install rails -v 2.3.1
now install Passenger and Nginx Web Server
sudo apt-get install libssl0.9.8
sudo passenger-install-nginx-module
follow the onscreen instructions, it would show you the ways to install missing packages.
After the missing packages are installed, run the above command again.
Enter choice 1
Press enter when asked for default path (/opt/nginx)
After completion nginx
Configuring Web Server at
cd /opt/nginx/conf/
I'm trying to deploy a rails project for the first time with Passenger. I've followed the guide on Passenger's site with the passenger gem and used 'passenger-install-apache2-module' and pasted the three lines into my httpd.conf. However, I noticed that when I tried to run passenger start in my project directory, it tried install passenger for nginx again, and when that finished, I was able to do 'passenger start'. The issue that I've noticed is that when I removed the three lines from my httpd.conf I was still able to run 'passenger start and seemingly to have started the server. My question hence becomes how would I determine if my passenger gem was installed for apache or nginx?
Thanks!
'passenger start' does not use your apache or nginx installation. It uses it's own in built webserver which is based on nginx. It starts on port 3000 by default.
I am trying to learn a bit of Ruby. I've installed Ruby on my Ubuntu machine and I am using apache. Everything works fine except to refresh a view I have to restart apache in the console and then hit ctrl-r, just pressing ctrl-r won't refresh the browser.
Apparently there's some caching going on, but does it have to be that way i.e. is it inherent to Ruby on Rails? I tried googling on this but it seems the only answer is to install some long-winded routine. For developing it seems like quite the tedious way to go.
Apache's a perfectly good choice for development.
Just install Passenger (mod_rails)...and follow the instructions...
I set it up for each site so that /etc/hosts contains
127.0.0.1 myapp
I use Apache virtual hosts with an entry like so - in /etc/apache2/sites-available/myapp
<VirtualHost *:80>
ServerName myapp
DocumentRoot /path/to/myapp/public
RailsEnv development
RailsAllowModRewrite off
<directory "/path/to/myapp/public">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
Enable and restart
sudo a2ensite myapp
sudo /etc/init.d/apache2 restart
That way, there's no running script/server ... it's just always running in dev mode - just point your browser to http://myapp
Don't use apache for development mode. Use script/server and install the mongrel gem (sudo gem install mongrel). Mongrel is faster than WEBrick and dumps the development log to the console in which it runs. It makes development decent.
Apache is not a good choice for development in cases like Rails, because you will indeed need to restart the server every time you change code. Rails ships with its own development server that you can start by executing (IIRC) script/server. It's much more suitable for development, as it needn't be restarted after every little change.
I'm using Apache with Passenger (aka modrails) for development purposes, and it works fine here. Just make sure to use Rails in development mode by setting "RailsEnv development" in your httpd.conf.
I use Apache with mod_fcgid. I found that going
$ touch ${MYAPP}/tmp/restart.txt
every time I want the app reloaded works for me.
I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.
Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby on Rails apps?
EDIT: At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks.
You could also look at proxying to Thin in the same way as detailed below. However, I've had some instabilities with Thin on Win, even though it's appreciably quicker. AB (Apache Benchmark) is your friend here!
Configuring Apache + Mongrel on Windows is not significantly different from *nix.
Essentially, you need to proxy requests coming into Apache to Mongrel. What this boils down to is something like this:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
ServerName www.myapp.comm
DocumentRoot "C:/web/myapp/public"
ProxyPass / http://www.myapp.com:3000/
ProxyPassReverse / http://www.myapp.com:3000/
ProxyPreserveHost On
</VirtualHost>
Stick this in your httpd.conf (or httpd-vhost.conf if you're including it).
It assumes you're going to run mongrel on port 3000, your Rails root is in C:\web\myapp, and you'll access the app at www.myapp.com.
To run the rails app in production mode:
mongrel_rails start -p 3000 -e production
And away you go (actually mongrel defaults to port 3000 so you could skip -p 3000 if you want).
The main difference is that you cannot daemonize mongrel on Windows (i.e. make it run in the background). Instead you can install it as a service using the mongrel_service gem.
Also, running a cluster is more complicated and you won't be able to use Capistrano. Let me know if you want more info.
I'm new to RoR and have been attempting the same thing on Windows Server 2008, here are some additional notes on getting mongrel going as a service:
if you get compilation errors when installing mongrel_service:
gem install mongrel_service
try using a binary instead by specifying your platform:
gem install mongrel_service --platform x86-mswin32
Additionally, to actually install the service you need to run this command in your RoR's app directory:
mongrel_rails service::install --name MyApp -e production -p 3001 -a 0.0.0.0
(or to remove:
mongrel_rails service::remove --name MyApp
)
Then you should be able to start/stop the app "MyApp" in your windows services control panel.
Hope that helps someone.
At the moment Mongrel does not work properly with Ruby 1.9 and will throw a "msvcrt-ruby18.dll not found" error when executing the command mongrel_rails.
Thin in this case seems to be the only option for now.
I just wanted to add this article to the list. It explains how to have Apache serve ruby files without the need to install any other applications.
http://editrocket.com/articles/ruby_apache_windows.html
You might want to try Bitnami RubyStack