Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the localhost ruby on rails server in internet?

I m using railsinstaller

http://localhost:3000/wage

Next page

http://localhost:3000/wage/results?hours=23

I try to access

myip:3000/wage 

But it shows ERR_CONNECTION_REFUSED

I get the myip from ipconfig-->ipv4

Is the url wrong or configuration problem?

like image 384
Monchhichi Avatar asked Feb 06 '23 03:02

Monchhichi


1 Answers

You've started well, but for local LAN only.

  1. For intranet only, you can use your LAN ip. Test it from another local machine (same LAN). Hope it works.

If your firewall and machine settings allow you to view on intranet, than go to next step:

  1. For internet, first make sure you have your public internet address, by visiting http://api.ipify.org/ > you will see your public IP address. Use it to access your website http://<public_address>:3000/

If it works on intranet, but not on internet, you need to open the port 3000 in your router and forward it to your local machine. (If you have no access to router settings, ask your administrator to help you with this).

Give me more details for a more complete solution. What OS are you using?

EDIT:

For Windows10 you have to make sure to open the port 3000 in your firewall.

  • Navigate to Control Panel, System and Security and Windows Firewall.
  • Select Advanced settings and highlight Inbound Rules in the left pane.
  • Right click Inbound Rules and select New Rule.
  • Add the port you need to open and click Next.
  • Add the protocol (TCP or UDP) and the port number into the next window and click Next.
  • On the "Profile" step select all 3 (Domain, Private, Public)
  • Select Allow the connection in the next window and hit Next.
  • Select the network type as you see fit and click Next.
  • Name the rule something meaningful (like: Allow incoming connections on port 3000) and click Finish.

To change the default 3000 port use:

rails server -p 8080 to change port

rails server -b 0.0.0.0 to bind 0.0.0.0 address

UPDATE:

When server starts will output to the console, the address:port it listens. example: Listening on tcp://0.0.0.0:3000 as a development server it can be set to listen on localhost requests only.

To override that settings use:

rails server -p <3030> -b 0.0.0.0 this will listen to all incoming connections on port 3030

For more details on the -p, and -b consult the help:

$ rails server -h
Usage: rails server [mongrel, thin etc] [options]
    -p, --port=port                  Runs Rails on the specified port.
                                    Default: 3000
    -b, --binding=IP                 Binds Rails to the specified IP.
                                    Default: localhost
    -c, --config=file                Uses a custom rackup configuration.
    -d, --daemon                     Runs server as a Daemon.
    -e, --environment=name           Specifies the environment to run this server under (test/development/production).
                                    Default: development
    -P, --pid=pid                    Specifies the PID file.
                                    Default: tmp/pids/server.pid
    -C, --[no-]dev-caching           Specifies whether to perform caching in development.
                                    true or false

    -h, --help                       Shows this help message.
like image 142
Codrut TG Avatar answered Feb 15 '23 23:02

Codrut TG