I am new to ruby on rails and running rails 2.3.5.My application is running at localhost:3000 ,but i want it should be run at "example.com" in brower when i start the serve normally as "script/ server" . What to do?
Thanks
I am new to ruby on rails and running rails 2.3.5.My application is running at localhost:3000 ,but i want it should be run at "example.com" in brower when i start the serve normally as "script/ server" . What to do?
Thanks
Open your /etc/hosts file in Linux. Windows is the same hosts file under some other directory.
Any how puts the next line in the file
127.0.0.1 example.com
Then if you “ping example.com” IP 127.0.0.1 will respond.
now you can use example.com:3000 to access your web site.
If you are not happy with your 3000 port then change Rails default http port setting.
I don’t know how to change this port number.
Open your /etc/hosts file in Linux. Windows is the same hosts file under some other directory. Any how puts the next line in the file 127.0.0.1 example.com Then if you “ping example.com” IP 127.0.0.1 will respond. now you can use example.com:3000 to access your web site. If you are not happy with your 3000 port then change Rails default http port setting. I don’t know how to change this port number.
It’s possible with iptables. Try out these rules:
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -d 127.0.0.0/8 -j REDIRECT --to-port 3000
sudo iptables -t nat -A OUTPUT -p tcp --dport 8080 -d 127.0.0.0/8 -j REDIRECT --to-port 80
First rule will redirect all local traffic from 80 to 3000.
The second will redirect 8080 to 80, to allow you access phpmyadmin or whatever you have on 80 port.
Tested on Ubuntu.
Open your /etc/hosts file in Linux. Windows is the same hosts file under some other directory. Any how puts the next line in the file 127.0.0.1 example.com Then if you "ping example.com" IP 127.0.0.1 will respond. now you can use example.com:3000 to access your web site.
Thanks .It helped me.
If you are not happy with your 3000 port then change Rails default http port setting. I don't know how to change this port number.
It's possible with iptables. Try out these rules:
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -d 127.0.0.0/8 -j REDIRECT --to-port 3000 sudo iptables -t nat -A OUTPUT -p tcp --dport 8080 -d 127.0.0.0/8 -j REDIRECT --to-port 80
First rule will redirect all local traffic from 80 to 3000. The second will redirect 8080 to 80, to allow you access phpmyadmin or whatever you have on 80 port.
Tested on Ubuntu.
Both exectued sussfully.Now can i access,rails application without port number 3000? If yes,what to do next?
Thanks
It tells to run the app on different ports,but i want to run it without giving any port like at "example.com"
Basics of the internet. http requests default to port 80. example.com is responding on port 80. Set you app to run on port 80.
B.
That's an implementation detail. All of the (non-secure) Web sites you visit that don't show a port use the *default* port 80.
If you want to be completely pedantic, the URL for the Apple home page is Apple. But when you type in www.apple.com, your browser first takes the leap of faith that you mean http:// (since it is a browser, after all) and then further assumes that you mean port 80, because you didn't top your URL with https:// or tail the domain with :443. Then, because you didn't enter a filename, the Apache server (or whatever they use there) looks up the DefaultIndex and fills that in for you, and performs a silent redirect (it doesn't tell you the exact details, so it could just as easily be index.php or index.erb or anything at all) to whatever that actual index file is, and THEN starts filling the sub-requests contained in that index file.
You can read a lot more about this at the Apache site, in the httpd project documentation. Pick the version you use there, and read up on mod_rewrite and its cousins.
Short answer, you can do this, it's done every day, and it's not that difficult. Slightly longer answer, you still haven't given any good reason why you would want to do this in the development environment. But have you looked at http://pow.cx/ for no-config local network hosting with a "real" domain?
Walter
Pow is just for Mac .I am running ubuntu 10.04,so unable to install and config it . Any solution?alternative?
Thanks
Start your rails server with http default port 80:
rails server -p 80
Now example.com should work.
I don’t why people write three pages of information without answering you anything
Thanks Alex, that helps a lot Simple isn't it rails server -p 80
Thanks again, any idea how I can achieve subdomains like basecamp
does? username.basecamphq.com
I didn't read all the basic DNS questions, but hopefully somebody pointed out that example.com won't be accessible externally.
Manoj,
I am glad that worked for you.
Take a look at this railscast for rails 3 subdomains
http://railscasts.com/episodes/221-subdomains-in-rails-3
Thanks,
Alex
Start your rails server with http default port 80: rails server -p 80
Now example.com should work.
I don’t why people write three pages of information without answering you anything
Because if you give a man a fish you feed him for a day. If you teach him to fish you feed him for life. The answer was in all the information provided and so was the answers to all the basic follow up questions.
B.
Thank you very much. It helped
i dont know why but "script/server -p 80" gives error me now as
amrit@ubuntu:~/amritdemo$ script/server -p 80 => Booting WEBrick => Rails 2.3.5 application starting on http://0.0.0.0:80 => Call with -d to detach => Ctrl-C to shutdown server [2011-04-22 09:20:01] INFO WEBrick 1.3.1 [2011-04-22 09:20:01] INFO ruby 1.8.7 (2010-01-10) [i486-linux] [2011-04-22 09:20:06] WARN TCPServer Error: Permission denied - bind(2) Exiting /usr/lib/ruby/1.8/webrick/utils.rb:73:in `initialize': Permission denied - bind(2) (Errno::EACCES) from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `new' from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners' from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `each' from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners' from /usr/lib/ruby/1.8/webrick/server.rb:75:in `listen' from /usr/lib/ruby/1.8/webrick/server.rb:63:in `initialize' from /usr/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize' from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/ webrick.rb:10:in `new' from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/ webrick.rb:10:in `run' from /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb: 111 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from script/server:3
why?
Thanks
i dont know why but "script/server -p 80" gives error me now as amrit@ubuntu:~/amritdemo$ script/server -p 80
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:80
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-04-22 09:20:01] INFO WEBrick 1.3.1
[2011-04-22 09:20:01] INFO ruby 1.8.7 (2010-01-10) [i486-linux]
[2011-04-22 09:20:06] WARN TCPServer Error: Permission denied -
bind(2)
Exiting
/usr/lib/ruby/1.8/webrick/utils.rb:73:in `initialize’: Permission
denied - bind(2) (Errno::EACCES)
from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `new’
from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners’
from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `each’
from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners’
from /usr/lib/ruby/1.8/webrick/server.rb:75:in `listen’
from /usr/lib/ruby/1.8/webrick/server.rb:63:in `initialize’
from /usr/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize’
from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/
webrick.rb:10:in `new’
from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/
webrick.rb:10:in `run’
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:
111
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require’
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require’
from script/server:3
why?
Linux/un*x systems require root privileges in order for a process to bind to “privileged” ports (any port number lower than 1024 (which is why rails and most other “development” and “testing” -mode processes use higher-numbered ports like 3000).
If you really want to run your rails app on port 80 using the command above, you’ll likely need to use “sudo”: sudo script/server -p 8
However, if you’re using RVM to manage your ruby and rubygems collections then you’d use its sudo wrapper “rvmsudo” that retains your “ruby environment” settings.
Edit the host file of your os to make example.com point a 127.0.0.1
this'll do it.
basically redirects port 80 to port 3000
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -d 127.0.0.1/8 -j REDIRECT --to-port 3000
tested and works