I'm sure this is a pretty basic question, but I could not find an answer to it. I already looked at this question, this question, this question, this question, and this question and none of them helped me reach an answer.
I am using Rails 4.2
. I created a very simple app to test out if I could do the following:
I wanted to see if it was possible for me to boot up my rails app on my computer, and then access the app from outside of my local network. For example: from my phone (which is not connected to the local network) I want to make a request and successfully get a response.
I assumed that I first needed to get my external/routable ip address. I realize that the IP address my ISP provides my router is not static, but just for demo purposes I wanted to see if I could just successfully make a single request.
I went to google and typed in "What is my ip" and it came back with my external ip address (let's pretend my external ip address is: 11.111.111.111
).
Within my rails app: I then did the following command:
rvmsudo rails s -p 80 -b 11.111.111.111
I want to bind to the external ip address, and I want to listen on port 80. I do the rvmsudo because, as I understand it, all ports below 1000 require higher privileges.
It errors out and says the following:
Can't assign requested address - bind(2)
I am trying to understand why this is erroring out. What am I not understanding? Am I missing a step? Is it not possible to do this? Is my ISP making it so that I cannot bind to that external IP? Do I need to do additional configuration on my router?
I realize that I could just use heroku. This is more of an experiment to see if this is even possible. Thanks in advance!
You can not bind the socket to your external IP. This IP is assigned to your modem (or whatever you use to connect to the internet) by your ISP. You can only bind to interfaces of your computer.
There are multiple solutions: