i am running webrick default ROR server inside vmware in ubuntu. i have host window as Window 10.but in window 10 browser i am not able to access the 0.0.0.0:3000 . i have ruby on rails code, how can i host in my own machine server?
in window10 browser i get error like-
[error][1]
[VMware and real host ip snapshot][2]
puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
plugin :tmp_restart
[1]: https://i.stack.imgur.com/N65uJ.png
[2]: https://i.stack.imgur.com/At2Rz.png
Related
I want to deploy RoR + React SPA to heroku as one project. As a typical production environment, use Nginx as web server and user Puma as app server.
I tried to follow readme of https://github.com/heroku/heroku-buildpack-nginx.
But after deployment, heroku popup an error
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Below are my configs
heroku buildpacks
heroku/nodejs # index 1
heroku/ruby # index 2
https://github.com/heroku/heroku-buildpack-nginx.git # index 3
Procfile
release: bundle exec rails db:migrate
web: bin/start-nginx bundle exec puma -C config/puma.rb
config/puma.rb
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
bind ENV.fetch('PUMA_SOCK') { 'unix:///tmp/nginx.socket' }
on_worker_fork do
FileUtils.touch('/tmp/app-initialized')
end
config/nignx.conf.erb => I removed unimportant config for this file because it is too long
http {
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
keepalive_timeout 5;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
}
EDIT: I think that the procfile should start Nginx too:
web: bin/start-nginx bundle exec puma -C config/puma.rb
Remember that for the nginx build pack you should disable the demon mode in the nginx.conf:
daemon off;
EDIT2: If that line doesn't work, try running Nginx directly (this is a hack, untested)):
web: bin/nginx -p . -c config/nginx.conf & ; bundle exec puma -C config/puma.rb
Also make sure the nginx logs are routed to stdout, placing this in the nginx.conf:
daemon off;
error_log /dev/stdout info;
http {
access_log /dev/stdout;
...
}
ORIGINAL:
As the documentation for the build pack states:
Basically, for webservers that are not designed for efficient, non-blocking I/O, we will benefit from having NGINX to handle all I/O operations
However, Puma is an efficient, non-blocking I/O server. You should be able to use it directly on a Heroku dyno.
The biggest advantage that Nginx could offer a Puma server is dealing with static files - which your configuration doesn't perform.
If you're not using Nginx for static files, you might decide to skip the extra latency added the Nginx proxy. Besides, Heroku's security features should (but might not) cover all the bases Nginx could offer you at this point.
If you need extra speed for static files - some Ruby servers (such as iodine or agoo) provide a fast static file service, allowing you to skip the Nginx layer and reduce latency.
I can not understand what the problem is. The app works perfectly after I start it. After a while of inactivity (around 5 min with no requests) the app stops responding when I send requests to it.
puma.rb:
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
This is what I get when I do this: ps aux | grep puma
user+ 4201 7.8 2.5 1197292 100560 ? Sl 15:41 0:04 puma 3.11.4 (tcp://0.0.0.0:3000) [backend]
user+ 4277 0.0 0.0 15476 1020 pts/20 S+ 15:42 0:00 grep --color=auto puma
ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
rails -v
Rails 5.1.6
OS Ubuntu 16.04 LTS
this is what your puma.rb should look like
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end
I want to be able to run two rails servers on one machine via vagrant and virtual box. I have the first set up and when i run
rails s
it returns the following with the site accessibly in my browser at http://localhost:3000/
=> Booting Thin
=> Rails 3.2.22.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
installing dummy notifier
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
Heres the vagrantfile for this instance:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
end
I now have the second project in a different folder on my local machine. I have navigated to it initiated my vagrant box, completed all the set up steps and ran rails s again. Here I get:
=> Booting Puma
=> Rails 4.2.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.12.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
Heres the vagrantfile for this instance:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
I have been trying to investigate the the fact that it says "listening on tcp://localhost:3000" but if anyone can give me some pointers as to how exactly I can run the two projects from the same machine it would be much appreciated.
You have to run them on different ports. rails s takes a port argument.
rails s -p 3001
will give you a server at port 3001 and so on.
Perhaps try running the second server at port 8080, not 3001, since your second vagrant machine is set up like :
config.vm.network "forwarded_port", guest: 80, host: 8080
I ended up running
puma -b tcp://0.0.0.0:3001
and my vagrantfile had the following:
config.vm.network "forwarded_port", guest: 3001, host: 3001
Thanks for the pointers though as they helped me to better understand the problem and find the solution.
I have a ruby on rails application and I am trying to run it on the external ip of my google compute engine ubuntu 14.04 LTS VM.
I try rails server -e production
and the output is:
=> Booting Puma
=> Rails 4.2.4 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.14.0 starting...
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://localhost:3000
I do not want it to be at that location; I want it to be viewable from the external ip address of the server.
Part of the issue is that I do not know if this is a rails, a puma, or a google compute engine question.
Note: I can't see if it actually launching at localhost:3000 because the VM is just a terminal.
(I am assuming you are using nginx, if not, apt-get install nginx; service nginx start)
If possible, show your nginx.conf (/etc/nginx/nginx.conf) and default.conf (/etc/nginx/sites-available/default.conf)
Since you are using puma (I use it too) you should setup nginx conf file and set server upstream equal to puma's binding.
# /etc/nginx/sites-available/default.conf
upstream your_app {
server 127.0.0.0.1:9292;
}
server {
listen 80;
server_name your_domain;
root /usr/share/nginx/your_app/public;
# or, if you are using capistrano
root /usr/share/nginx/your_app/current/public;
location / {
proxy_pass http://your_app; # equal to upstream "name"
...
}
....
}
# config/puma.rb
[...]
bind "tcp://127.0.0.1:9292"
And execute puma's server
$ bundle exec puma RAILS_ENV=production &
After doing this steps and if the application still doesn't work, output your /var/log/nginx/error.log, nginx.conf and default.conf
What is going on with this dump when I am running Puma for my Rails server in development. I find my app starts being really slow in development and I have to restart the server every once and a while. So I'm curious about what is going on with this dump and how can I make my Puma server act better in development?
This is my Procfile
web: bundle exec puma -C config/puma.rb
This is my Puma.rb file
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 8)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end