Nginx Passenger not serving Rails application - ruby-on-rails

I setup Nginx with passenger on centos 7 VPS. I installed nginx and passenger as a gem. In addition I installed passenger-install-nginx-module.
When I start sudo service nginx and type passenger-status I get "Phusion Passenger is currently not serving any applications.". From my nginx conf file
http {
passenger_root /usr/local/rvm/gems/ruby-2.4.1/gems/passenger-5.1.8;
passenger_ruby /usr/local/rvm/gems/ruby-2.4.1/wrappers/ruby;
passenger_app_env production;
passenger_instance_registry_dir /var/lib/passenger-instreg;
...
server {
listen 80;
server_name localhost;
root /home/myuserhere/current/public;
passenger_enabled on;
File passenger.* creates normally when I restart nginx.
echo $PASSENGER_INSTANCE_REGISTRY_DIR returns the same path as in nginx conf file.
What I do wrong that passegner does not start application?

Finally I got it. Everything was all right. Passenger does not start apps during startup, but during the first request so all I needed to do it was press enter in my browser ... Hope that answer save time to others.

I was having a similar problem; where passenger wasn't serving any applications. This is on Focal, rails 6, Ruby 3.0.1, passenger-version: 6.0.8.
Turns out that it will start serving requests upon first request. So all I did was to temporarily allow http on the UFW then used 'curl' to http a request. Once the landing page was displayed, I was good to go.

Related

ROR - The Phusion Passenger application server encountered an error while starting your web application

When i upload my ROR code in server and run my website that time i face this type of error.
The Phusion Passenger application server encountered an error while starting your web application.
Because you are running this web application in staging or production mode
You need to define the mode of environment in nginx configuration.
server{
listen 80 default_server;
passenger_enabled on;
passenger_app_env production;
root <path to application folder>;
}
If you see passenger_app_env is set to production.
For more details, could you please share the nginx error logs ?

Why Nginx response extremely slow while accessing my Rails app (Both running on same Windows machine)?

I have both a working Rails 4 application (http://localhost:3000) and Nginx server (http://localhost:80) accessible through the browser.
Nginx has been configured as reverse proxy with my Rails 4 app so that http://localhost actually reaches my rails application http://localhost:3000. Now, this is working fine but the web pages get displayed extremely slowly whenever I access the application through Nginx. I have configured Tomcat with Apache Web Server in past and never slowness problem before and practically speaking Nginx is said to much lighter and faster than Apache Web Server.
This makes me think if I have configured my Rails app with Nginx correctly?
Modified nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://localhost:3000;
}
...
...
}

Faye-rails, ngnix, passenger slow responce from faye

I want to create a simple chat.
I am not a guru of server administration.
So I have a question about ngnix and faye.
I use ngnix + passenger for my production server. I have a droplet on digitalocean and want deploy my application on this.
So for deployment I use official passenger tutorial https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/
For model callbacks I use faye-rails gem. Like faye-rails say if I use passenger, I need use this configuration
config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'} do
map '/announce/**' => SomeController
end
In my development localhost:3000 chat works perfectly fast. But when I deploy it, it works very slowly(the response comes in the interval of 5 to 60 seconds). I dont know how to fix it.
In my /etc/ngnix/sites-enabled/myapp.conf I use this config:
server {
listen 80;
server_name server_ip;
# Tell Nginx and Passenger where your app's 'public' directory is
root /project_path_to_public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /ruby_wrapper_path;
}
Need I upgrade my /etc/ngnix/sites-enabled/myapp.conf and how? Or what I need to do?
I'm currently using Faye and Redis on an application I'm developing. This is not a direct solution to the question's current setup, but an alternative method that I have implemented. Below is my nginx configuration and then I have Faye running via rackup in a screen on the server.
/etc/nginx/sites-enabled/application.conf:
server {
listen 80;
listen [::]:80;
server_name beta.application.org;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/application/current/public;
# Turn on Passeger
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;
rails_env production;
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:9292;
}
server {
listen 8020;
location / {
proxy_pass http://127.0.0.1:9292/push;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
This link should provide a little insight into how it works.
https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/
You can also reference the Faye github for some guidance on setting it up with Passenger.
Also, if you followed the Digital Ocean tutorials for initial server setup and ended up enabling your firewall, please ensure you allow the ports you have Faye/websockets running on. (See here under configuring a basic firewall: Additional Recommended Steps for New Ubuntu 14.04 Servers
My alternative method involves running Faye in a separate screen on the server. A few commands you will need to manage screens on an ubuntu server are:
screen -S <pick screen name> (new screen)
screen -ls (lists screens)
screen -r <screen number> (attach screen)
to quit from a screen, ctrl + a THEN "d" (detach screen)
Once you have a new screen running, run the Faye server in that screen using rackup: rackup faye.ru -s thin -E production
As a note, with this option, every time you restart your Digital Ocean server (i.e. if you create a screenshot as a backup), you will need to create a new screen and run the faye server again; however, using something like Daemon would be a better implementation to circumvent this (I merely haven't implemented it yet...). Head over to Github and look for FooBarWidget/daemon_controller.
Let me know if you have any other questions and I'll try to help out!

Rails Cloud Server - Installed NGINX but rails app still uses WEBrick

So I've bought and set up my DigitalOcean Ubuntu 14.04 Droplet, set up SSH keys, bought a domain name, transfered my app to the DigitalOcean cloud server using Filezilla and install Passenger with NGINX. It took a lot of trial, error and research but I've learned a lot from it.
The problem is, I still can't get the it to work! When I start my $rails s -e production in the cloud, I noticed it still uses Webrick despite already installing NGINX. I also get a 500 Internal Service Error from NGINX when I visit my website's IP address.
Its likely that I did something wrong, but due to my inexperience, I have no way of really knowing what procedure was incorrect/skipped. Maybe something with Capistrano? my secret keys still need some work done, not sure :/
Can someone help me out?
My checklist:
Install Ruby and Rails and bundle install in my Cloud Server [done]
Install NGINX and Passenger following the tutorial at: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04 [done]
Edited my NGINX config file to:
server {
listen 80 default_server;
server_name 45.55.136.43;
passenger_enabled on;
passenger_app_env production;
root /origins/public;
}

Nginx - Basic Configuration

I've just deployed a Rails application using Capistrano under /home/username/app_name.
Now, I'm not quite sure on how to setup Nginx, I've followed this tutorial, http://coding.smashingmagazine.com/2011/06/28/setup-a-ubuntu-vps-for-hosting-ruby-on-rails-applications-2/comment-page-1/#comment-594321. I have this on my nginx.conf file, I modified the first server block I saw:
server {
listen 80;
server_name www.yourdomain.com;
root /home/johndoe/test_app/current/public;
passenger_enabled on;
...
}
But now, I'm not sure how to procede. What exactly is the server_name in the example above? And how should I access the application? I've tried typing in my ip address and nothing shows up. I'm using Linode by the way. And how do I set up the nameservers for my domain? Detailed explanations and tutorials would be very helpful. Thanks in advance!
server_name on Nginx is exactly the same as ServerName in Apache, i.e. the domain name you'd like to use for this directory (named virtual host).
With passenger set to on you should be able to access the application directly via the domain.

Resources