Getting Rails production to run on port 80 - ruby-on-rails

I'm trying to get my rails app to run in production mode but I've been having a bit of difficulty.
I'm using passenger with apache and am running Ubuntu 12.04. I have my production database configured and created, and passenger set up. Status is as follows:
$ rvmsudo passenger-status
Version : 4.0.56
Date : 2014-12-25 01:54:20 +0000
Instance: 7264
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
However when I run rails server -e production, it still listens on port 3000 see below:
$ rails server -e production
=> Booting WEBrick
=> Rails 4.2.0 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-12-25 01:54:49] INFO WEBrick 1.3.1
[2014-12-25 01:54:49] INFO ruby 2.1.5 (2014-11-13) [i686-linux]
[2014-12-25 01:54:49] INFO WEBrick::HTTPServer#start: pid=7459 port=3000
What might I be missing to get it to listens on port 80 in production mode?
Many thanks in advance.

I don't think this is how you have to start the server in production using Apache. Did you install apache-paassenger modules? and made changes in apache conf file?
First, the gem needs to be installed on the system:
gem install passenger
Before the Apache module is compiled, two dependency packages need to be installed as well:
apt-get install curl-devel httpd-devel
Use this command to start the apache installation: It will take some time
passenger-install-apache2-module
Passenger will display some content after Apache installs:
Follow it up and make changes in (/etc/httpd/conf/httpd.conf)
You will have to point to application public folder and restart the apache server follow with these sources closely.
https://www.digitalocean.com/community/tutorials/how-to-install-rails-apache-and-mysql-on-ubuntu-with-passenger
https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6
It helped when I did it for first time.

Related

Terminal does not work after running rails server

after running "rails server" on my mac to start my application, my terminal does not allow me to write commands in the terminal. All I get is the following, with the problem that I can not write any commands.
Last login: Mon Jan 2 13:19:07 on ttys001
Nicholass-MacBook-Pro:~ nicholaswenzel$ cd last_test
Nicholass-MacBook-Pro:last_test nicholaswenzel$ cd nofuckingidea
Nicholass-MacBook-Pro:nofuckingidea nicholaswenzel$ rails s
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-01-02 13:23:18] INFO WEBrick 1.3.1
[2017-01-02 13:23:18] INFO ruby 2.2.3 (2015-08-18) [x86_64-darwin15]
[2017-01-02 13:23:18] INFO WEBrick::HTTPServer#start: pid=8743 port=3000
Can anyone help?
You can start your server in a background:
rails server &
But, usually, this problem can be resolving by starting an additional terminal process (open new terminal window or tab). In this case, you'll be able to see server logs in runtime.

Rails server is running but cannot connect to it in web browser in Ubuntu 14.04

I am new to Ubuntu 14.04. I am trying to set-up Ruby on Rails on Ubuntu 14.04 and I am using an Azure virtual machine. Everything is done. I installed Ruby, Rails and Bundler.
When I start the server it runs perfectly but I cannot see the "WELCOME ABOARD" or any start page and I cannot connect it through my browser.
When I run rails s Webrick starts successfully and it says:
=> Booting WEBrick
=> Rails 4.2.5.1 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
[2016-01-29 20:47:14] INFO WEBrick 1.3.1
[2016-01-29 20:47:14] INFO ruby 2.2.3 (2015-08-18) [x86_64-linux]
[2016-01-29 20:47:14] INFO WEBrick::HTTPServer#start: pid=1655 port=3000
I also tried binding it with my public address. I tried everything I know.
Cannot connect to localhost from aside.
Try start rails with following arguments:
rails s -b {PUBLIC IP} -p 3000
where {PUBLIC IP} is IP address of your server

My server is starting Webrick instead of Unicorm/Nginx on production

I've followed these steps in order to have a Unicorn/Nginx app running:
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04
I've done everything indicated there with exception of the databases instructions (because I'm going to use Mongo). However when I execute (ip edited):
RAILS_ENV=production rails server --binding=123.456.789.01
a Webrick server is started:
/home/username/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.0.2/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
=> Booting WEBrick
=> Rails 4.0.2 application starting in production on http://123.456.789.01:3000
=> Run `rails server -h` for more startup options
Is there something I need to check to get the production setup working fine? I don't know what I need to verify.
I believe you have skipped some steps in the tutorial you have mentioned... After you install unicorn and nginx you should be able to start them:
sudo service unicorn_appname start
sudo service nginx restart

Why can't I connect to my Heroku rails app when I run the server manually?

In trying to debug another problem, I've tried starting up my Heroku Rails app from the command line using heroku run rails server. The output seems fine, as follows, but attempts to connect to it from the browser fail. If I don't specify a port number, I get the generic "application error" page from Heroku. If I try to connect on port 3000, the browser tells me it cannot connect.
Here's the output to the console after starting up the server:
Running `rails server` attached to terminal... up, run.9912
=> Booting WEBrick
=> Rails 4.0.1 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-11-18 01:52:55] INFO WEBrick 1.3.1
[2013-11-18 01:52:55] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
[2013-11-18 01:52:55] INFO WEBrick::HTTPServer#start: pid=2 port=3000
I did note the all zeros IP address.
I am unaware of any ability to run Heroku in the fashion you describe. In my experience, you deploy when you push your code the the Git remote on Heroku, and the code runs according to the Procfile you provide in the codebase. Then Heroku configures all kinds of environment settings to enable your app to run properly.
Once there, you can also do a heroku restart for whatever reason.
Incidentally, you probably would be better off ditching WEBrick for Unicorn or Thin.
If seems you're running your app like a localhost process from Heroku...If I'm not mistaken.
Why don't you just run through
heroku run ps:scale web=1

Webrick Fails to Run as Daemon, no Error Message

Running Ubuntu Server 10.04 with Rails 2.3.4 and Webrick 1.3.1; our rails app runs fine when called via script/server -e production, but trying to test it as a daemon by calling it with the -d flag produces the following output:
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
Nothing is produced in the logs, and other Rails applications will run detached without issue.
I assume You are running the Webrick in port 3000
>>$ sudo netstat -anp | grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 8822/ruby
>>$ sudo kill -9 8822
I don't mean to contradict your choosing Webrick as a production server and maybe there is something I'm missing about why you are choosing Webrick, but have you considered other alternatives? I'd wager you already know all of this, but Webrick is the provided ruby server, and it is also the slowest ruby server choice.
Some of the most popular production server choices are:
Passenger
Thin
Mongrel
Unicorn
Glassfish
Passenger is likely the most popular choice for production now due to its easy configuration, speed, and features.
If there is a specific use case for Webrick that makes it better than any of the other server choices, I'd love to know.
You can add patch to enable error log here: https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/core_ext/process/daemon.rb#L16
To
unless noclose
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
STDERR.reopen '/tmp/rails_daemon_err.log', 'a'
end
Now when you start rails server with -d, the error log will append to /tmp/rails_daemon.log.

Resources