How to start rails server on some other port? - ruby-on-rails

I want to start rails sever on port other that 3000 so that I can run two applications simultaneously on my machine. One is running on server using port 3000 and 2nd with new port.

Use the -p option:
rails server -p 3001

rails s -p <port_number>

Related

expose docker container's application url to host

I have a docker image with some ruby on rails environment built in (i.e. installing some rails gems and system packages) and I have an EXPOSE 3000 to expose the port at the end.
I ran a container with docker run -p 3000:3000 -ti <image> bash, then start the rails server. The logs are saying the web server is available on localhost:3000. I tried to connect to both the IPAddress as specified in docker inspect <id> and localhost on my host machine, but neither would be able to connect. What could be the problem here?
If your application is listening on localhost, it will only respond to requests from the container's localhost - that is, other processes inside the container.
To fix this you need to set the listen address of your server to listen to any address (usually, you specify this as 0.0.0.0). I've never used rails, but from a quick search, you should use the -b option.
So changing your ENTRYPOINT or CMD in your Dockerfile to contain -b 0.0.0.0 would probably do it.

How to run Rails server on different ports with address on Ubuntu

I want to run my Rails server on different ports with different addresses. I need to run it on port 8888 and address 10.XX.XX.XXX for all time, in other words, once I start the server, it should run until the server is not stop [sic]. I am running this on Ubuntu machine. Please help me resolve this problem.
Try this:
rails s -p 8888 -b 10:xx:xx:xx
And if you want to run the server in background, then use
rails s -p 8888 -b 10:xx:xx:xx -D
You could try to run it on rails s -p 8888 and it will be available on your server address on port xxx.xx.xxx.xx:8888

How to start a Rails server forever on Ubuntu

I have uploaded my Rails app on my Ubuntu server, where I want to keep my Rails server running so that any one can access it at any time.
I tried the command below to run my app:
rails server --binding=oditek.in -p 8888
Please help me to make this possible.
You can try following option to run the server in background.
rails s -d ## With default Port.
rails s -p 8888 -d ## With Custom port.
Or
nohup rails s &
Or
You can also configure your project with Nginx + Passenger

I have a ruby on rails web application work at port 3000 I want to make it works at port 80

I have a ruby on rails web application work at port 3000 I want to make it works at port 80
What is the easiest way to make it happend ?
I've tried to change port 3000 in file
C:\Ruby187\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\bin\mongrel_rails
But every thing crashed up so i've changed it back to 3000
Since you are using rails 1.8.7. you should do like this mongrel_rails start -p 80
you can also find more available options by doing mongrel_rails start -h
you can specify the desired port with the -p parameter
rails s -p 80

How to run rails s -p80 on 80 port?

By default,
rails s #running on 3000 port
Now I want to run it on port 80. So I tried:
sudo rails -s -p80
But it threw an error:
mlzboy#mlzboy-MacBook ~/my/b2c2 $ sudo rails s -p80
sudo: rails: command not found
I used rvm to install ruby & rails. It seems rvm is user specified. Is it not able to find rails in root?
I also tried below code:
mlzboy#mlzboy-MacBook ~/my/b2c2 $ which rails
/home/mlzboy/.rvm/gems/ruby-1.9.2-p0/bin/rails
mlzboy#mlzboy-MacBook ~/my/b2c2 $ sudo /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/bin/rails s -p80
rvmsudo rails server -p 80
Just forward the request from port 80 to 3000 using below command:
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
Another option is:
rvmsudo rails server -p 80
However please remember to free this port from Apache or other services which consume this port normally. Also, I m not sure giving sudo permission to RVM may have any security issue or not?
Was going to suggest
rails=`which rails` ; sudo $rails server -p 80
but that still tries to use the global gemset and not the project gemset from RVM. So...
Make sure sshd is running on your Mac. (System Prefs => Sharing => Remote Login checked)
Make sure rails s is running on port 3000 as your non-root user
Open a new terminal and...
me=``whoami``; sudo ssh -L 80:127.0.0.1:3000 -l $me -N localhost
(BTW reduce the duplicate `'s to singular ones in the line above, I cannot figure out how escape it properly here.)
The first Password: is your root user, the second is the password for whomever whoami returns.
Though you probably want to install Phusion Passenger and set it up under your local Apache. Unless you are just trying to demo something real quick and this is not a permanent solution of course.
If you are using RVM, and you did the default setup, then you shouldn't use sudo.
Just:
mlzboy#mlzboy-MacBook ~/my/b2c2 $ rails server -p 80
However 80 is a privileged port, so you need to run as root, and you will have follow the instructions for Multi-User installation of RVM.
you can start server on port 80
rails s -p 80
If port 80 does not bind(other processes is not using to port 80).

Resources