Forum: Ruby on Rails How to change the url (from localhostL:3000) to (example.com)

Posted by amritpal p. (amritpal_p)
on 2011-04-18 12:13
(Received via mailing list)
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
Posted by Alex Katebi (Guest)
on 2011-04-19 06:45
(Received via mailing list)
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.

On Mon, Apr 18, 2011 at 5:51 AM, amrit pal pathak 
<amritpalpathak1@gmail.com
Posted by Alexander G. (cutalion)
on 2011-04-19 10:10
(Received via mailing list)
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.
Posted by amritpal p. (amritpal_p)
on 2011-04-19 17:59
(Received via mailing list)
On Apr 19, 4:09am, Alexander <cutal...@gmail.com> wrote:
> 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.
> 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
Posted by Bryan Crossland (Guest)
on 2011-04-20 14:52
(Received via mailing list)
On Tue, Apr 19, 2011 at 10:57 AM, amrit pal pathak <
amritpalpathak1@gmail.com> wrote:

>        Thanks .It helped me.
> > --to-port 3000
> without port number 3000?
>        If yes,what to do next?
>
>
Here you go. Amazing what you find on the Internet these days.

http://tinyurl.com/3bp7nsh

B.
Posted by amritpal p. (amritpal_p)
on 2011-04-20 18:33
(Received via mailing list)
On Apr 20, 8:51am, Bryan Crossland <bacrossl...@gmail.com> wrote:
> amritpalpath...@gmail.com> wrote:
> > > If you are not happy with your 3000 port then change Rails default http
> > > sudo iptables -t nat -A OUTPUT -p tcp --dport 8080 -d 127.0.0.0/8 -j
> >    If yes,what to do next?
>
> Here you go. Amazing what you find on the Internet these days.
>
> http://tinyurl.com/3bp7nsh
       It tells to run the app on different ports,but i want to run it
without giving any port like at "example.com"
Posted by Bryan Crossland (Guest)
on 2011-04-20 18:47
(Received via mailing list)
On Wed, Apr 20, 2011 at 11:31 AM, amrit pal pathak <
amritpalpathak1@gmail.com> wrote:

> >
> > > > Then if you "ping example.com" IP 127.0.0.1 will respond.
> > > > Try out these rules:
> > > > whatever you have on 80 port.
>        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.
Posted by Walter Davis (walterdavis)
on 2011-04-20 19:15
(Received via mailing list)
On Apr 20, 2011, at 12:31 PM, amrit pal pathak wrote:

>> Here you go. Amazing what you find on the Internet these days.
>>
>> http://tinyurl.com/3bp7nsh
>       It tells to run the app on different ports,but i want to run it
> without giving any port like at "example.com"

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 http://www.apple.com:80/index.html. 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
Posted by amritpal p. (amritpal_p)
on 2011-04-21 16:37
(Received via mailing list)
On Apr 20, 12:55pm, Walter Lee Davis <wa...@wdstudio.com> wrote:
>
> and THEN starts filling the sub-requests contained in that index file.
>
Pow is just for Mac .I am running ubuntu 10.04,so unable to install
and config it .
 Any solution?alternative?

Thanks
Posted by Alex Katebi (Guest)
on 2011-04-21 17:56
(Received via mailing list)
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 :)

On Tue, Apr 19, 2011 at 11:57 AM, amrit pal pathak <
Posted by Manoj Sachwani (Guest)
on 2011-04-21 20:56
(Received via mailing list)
Thanks Alex, that helps a lot :) Simple isn't it rails server -p 80 :P
Thanks again, any idea how I can achieve subdomains like basecamp
does? username.basecamphq.com
Posted by PsiPro (Guest)
on 2011-04-21 21:09
(Received via mailing list)
http://railscasts.com/episodes/221-subdomains-in-rails-3

I didn't read all the basic DNS questions, but hopefully somebody
pointed out that example.com won't be accessible externally.
Posted by Alex Katebi (Guest)
on 2011-04-21 21:14
(Received via mailing list)
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
Posted by Bryan Crossland (Guest)
on 2011-04-22 03:47
(Received via mailing list)
Sent from my iPhone

On Apr 21, 2011, at 10:54 AM, Alex Katebi <alex.katebi@gmail.com> wrote:

> 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.
Posted by amritpal p. (amritpal_p)
on 2011-04-22 13:59
(Received via mailing list)
On Apr 21, 11:54am, Alex Katebi <alex.kat...@gmail.com> wrote:
> 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 :)

      Thank you very much.
       It helped
Posted by amritpal p. (amritpal_p)
on 2011-04-22 15:21
(Received via mailing list)
On Apr 22, 7:58am, amrit pal pathak <amritpalpath...@gmail.com>
wrote:
> On Apr 21, 11:54am, Alex Katebi <alex.kat...@gmail.com> wrote:
>
> > 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 :)

       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
Posted by Kendall Gifford (zettabyte)
on 2011-04-22 17:57
(Received via mailing list)
> [2011-04-22 09:20:06] WARN  TCPServer Error: Permission denied -
> from /usr/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize'
> 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.
Posted by Radhames Brito (rbritom)
on 2011-04-23 02:29
(Received via mailing list)
Edit the host file of your os to make example.com point a 127.0.0.1
Posted by John Griffiths (indiehead)
on 2013-03-13 04:30
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.