Rails/Nginx/Passenger ERROR: Phusion Passenger doesn't seem to be running - ruby-on-rails

I was setting up Passenger and Nginx for my Rails App (Mac OS X 10.11).
I used these commands:
gem install passenger
rvmsudo passenger-install-nginx-module
All these gets installed perfectly.
Added nginx path in .bash_profile:
export PATH=$PATH:/opt/nginx/sbin/
My nginx conf:
passenger_root /Users/MyUserName/.rvm/gems/ruby-2.2.5#rails4115/gems/passenger-5.3.4;
passenger_ruby /Users/MyUserName/.rvm/gems/ruby-2.2.5#rails4115/wrappers/ruby;
server {
listen 443;
ssl on;
server_name app1-local.staging.com;
rails_env development;
passenger_enabled on;
root /Users/MyUsername/Desktop/Github/MainApp/public;
ssl_certificate /opt/nginx/ssl/mainapp.com.crt;
ssl_certificate_key /opt/nginx/ssl/mainapp.com.key;
}
server {
listen 443;
ssl on;
server_name app2-local.staging.com app3-local.staging.com app4-local.staging.com local.staging.com;
rails_env development;
passenger_enabled on;
root /Users/MyUsername/Desktop/Github/MainApp2/public;
ssl_certificate /opt/nginx/ssl/mainapp.com.crt;
ssl_certificate_key /opt/nginx/ssl/mainapp.com.key;
}
server {
listen 80;
server_name app1-local.staging.com;
rails_env development;
passenger_enabled on;
root /Users/MyUsername/Desktop/Github/MainApp/public;
}
server {
listen 80;
server_name app2-local.staging.com app3-local.staging.com app4-local.staging.com local.staging.com;
rails_env development;
passenger_enabled on;
root /Users/MyUsername/Desktop/Github/MainApp2/public;
}
After this I started nginx: sudo nginx, it worked. Now if I visit local.staging.com, I get 502 internal server error.
Nginx error logs displays:
upstream prematurely closed connection while reading response header from upstream
If I do passenger-status, it outputs:
Phusion Passenger is currently not serving any applications.
Note: on running, passenger-config validate-install command, it says Everything looks good. :-)
EDIT
Output of sudo passenger-memory-stats:
-------- Apache processes --------
----------- Nginx processes ------------
PID PPID VMSize Resident Name
62366 1 2411.6 MB 1.3 MB nginx: master process nginx
63016 62366 2411.6 MB 1.5 MB nginx: worker process
63008 28339 2377.8 MB 0.3 MB tail -f /opt/nginx/logs/error.log
------ Passenger processes ------
PID VMSize Resident Name
36415 0.0 MB 0.0 MB (PassengerAgent)
63010 2416.8 MB 3.3 MB Passenger watchdog
63014 2417.6 MB 3.3 MB Passenger ust-router
63602 2457.3 MB 5.7 MB Passenger core
EDIT 2
Now in nginx error.log, getting:
Process aborted! signo=SIGSEGV(11), reason=#0, signal sent by PID 0 with UID 0, si_addr=0x0, randomSeed=1534502322
And
upstream prematurely closed connection while reading response header from upstream
Any help here?

Related

Nginx passenger integration mode always require Passengerfile.json file?

I've followed this installation guide to setup nginx and passenger integration mode:
https://www.phusionpassenger.com/library/install/nginx/install/oss/el7/
I'm aware that "Passenger in its Nginx integration mode is to be configured via the Nginx configuration file. There is no configuration file that is specific to Passenger only" => No Passengerfile.json in root application directory.
But after configured passenger.conf and virtual host config and started nginx, the errors occurred:
2019/05/29 09:13:22 [alert] 16126#0: *3 Error opening '/home/deploy/my-app/current/Passengerfile.json' for reading: Permission denied (errno=13); This error means that the Nginx worker process (PID 16126, running as UID 997) does not have permission to access this file
I've tried to give permissions to nginx worker process following this instruction: https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/#upon-accessing-the-web-app-nginx-reports-a-permission-denied-error
But can't solve the problem.
My passenger.conf inside /etc/nginx/conf.d
passenger.conf
# To enable the Phusion Passenger application server (www.phusionpassenger.com),
# install the following package:
#
# yum install passenger
#
# Then uncomment these options:
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
passenger_instance_registry_dir /var/run/passenger-instreg;
My app configuration file:
server {
listen 80;
listen [::]:80;
server_name myapp.com;
root /home/deploy/my-app/current/public;
passenger_enabled on;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
rails_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs|uploads) {
expires max;
gzip_static on;
}
}
passenger-memory-stats
---------- Nginx processes -----------
PID PPID VMSize Private Name
--------------------------------------
16121 1 113.5 MB 0.6 MB nginx: master process /usr/sbin/nginx
16125 16121 113.7 MB 0.8 MB nginx: worker process
16126 16121 113.7 MB 0.8 MB nginx: worker process
### Processes: 3
### Total private dirty RSS: 2.13 MB
----- Passenger processes -----
PID VMSize Private Name
-------------------------------
16109 355.0 MB 2.1 MB Passenger watchdog
16112 923.4 MB 4.0 MB Passenger core
### Processes: 2
### Total private dirty RSS: 6.11 MB
passenger-config restart-app /home/deploy/my-app
There are no Phusion Passenger-served applications running whose paths begin with '/home/deploy/my-app'.
Thanks in advance!
We were having the same issue; solved by adding missing execute permissions to the user home directory. Hope this helps
chmod o+x $HOME
All directories above your application directory need to have world execute permissions.
This is the permission error to resolve it run the following command in you ec2 instance or any other machine.
1. Become root user:
sudo -i
Go to home directort:
cd /home
Give execute permission to your user home directory:
chmod g+x,o+x ec2-user
Now restart you server nginx
sudo kill $(cat /opt/nginx/logs/nginx.pid)
sudo /opt/nginx/sbin/nginx

Passenger + NGINX: Phusion Passenger is currently not serving any applications

Phusion Passenger + NGINX in production environment
I have done everything as usual with my ROR-application, but passenger not working with it. Have no idea whats wrong...
sudo passenger-config restart-app
Phusion Passenger is currently not serving any applications.
/etc/nginx/sites-available/myapp
server {
listen 80;
server_name _;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/myapp/public;
passenger_app_root /var/www/myapp;
rails_env production;
passenger_enabled on;
passenger_ruby /home/myuserapp/.rvm/gems/ruby-2.3.1/wrappers/ruby;
}
In sites-enabled have a soft symlink myapp to /etc/nginx/sites-available/myapp
sudo passenger-status
Version : 5.1.4
Date : 2017-05-25 06:56:30 +0300
Instance: byXevAbZ (nginx/1.10.3 Phusion_Passenger/5.1.4)
----------- General information -----------
Max pool size : 6
App groups : 0
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
But have some passenger instances running...
sudo passenger-config list-instances
Name PID Description
--------------------------------------------------------------------------
byXevAbZ 1085 nginx/1.10.3 Phusion_Passenger/5.1.4
I ran sudo nginx -t command
nginx: [warn] conflicting server name "_" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
First warning cofused me, so i decide the problem is in conflict myapp-site and defult one.
So i just turn of default site and restart nginx. And everything worked!
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
Final config file:
/etc/nginx/sites-available/myapp
server {
listen 80;
server_name myapp.com;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/myapp/current/public;
rails_env production;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/myuserapp/.rvm/gems/ruby-2.3.1/wrappers/ruby;
}
P.S. Correct me if you understand the subject deeper.

passenger wont find public path

I'm trying to setup my rails server and passenger wont recognize my app giving this error on log:
[error] 1473#1473: *1 "/home/myapp/public/index.html" is not found (2: No such file or directory)
or a 404 error in client.
i've done all troubleshooting possiilities to resolve but nothing.
here is my server block:
server {
listen 80;
server_name mydomaiin.com;
rails_env development;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/myapp/.rbenv/versions/2.4.0/bin/ruby;
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/myapp/public;
}
can anyone help me?
thanks
As your root dir is in /home/myapp/myapp, update your server conf:
server {
listen 80;
server_name mydomaiin.com;
rails_env development;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/myapp/.rbenv/versions/2.4.0/bin/ruby;
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/myapp/myapp/public;
}

504 Gateway Time-out nginx/1.4.6 (Ubuntu)

Follow rails one app click deployment. Database done well, even I check rails console everything working fine.
Ruby version is 2.3.0 and rails version is 5.0.1
But when I hit IP address it gives an error time out
on check unicorn logs I get
/usr/local/rvm/gems/ruby-2.2.1/gems/unicorn-5.0.1/bin/unicorn:126:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `load'
/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `<main>'
/usr/local/rvm/gems/ruby-2.2.1#global/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1#global/bin/ruby_executable_hooks:15:in `<main>'
E, [2017-02-26T15:47:18.969274 #9861] ERROR -- : reaped #<Process::Status: pid 11928 exit 1> worker=2
I, [2017-02-26T15:47:18.969471 #9861] INFO -- : worker=2 spawning...
I, [2017-02-26T15:47:18.974112 #11942] INFO -- : worker=2 spawned pid=11942
I, [2017-02-26T15:47:18.978540 #11936] INFO -- : Refreshing Gem list
I, [2017-02-26T15:47:18.986558 #11938] INFO -- : Refreshing Gem list
and nginx error is
017/02/26 15:34:17 [error] 18564#0: *31 connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 121.52.156.57, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock:/", host: "188.166.157.124"
2017/02/26 15:35:42 [error] 32360#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.155.34.115, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
2017/02/26 15:42:38 [error] 6296#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.152.140.90, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
unicorn.conf
listen "unix:/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/company_startup"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"
ps aux | grep unicor
rails 4751 18.0 4.2 172880 21516 ? R 14:59 0:00 unicorn worker[2] -D -c /etc/unicorn.conf -E production
rails 4757 0.0 4.1 172404 20972 ? Rl 14:59 0:00 unicorn worker[3] -D -c /etc/unicorn.conf -E production
rails 4760 0.0 2.9 159860 14568 ? Rl 14:59 0:00 unicorn worker[1] -D -c /etc/unicorn.conf -E production
root 4764 0.0 0.1 11712 620 pts/0 S+ 14:59 0:00 grep --color=auto unicorn
root 20463 0.4 2.6 146740 13176 ? Sl 04:32 2:48 unicorn master -D -c /etc/unicorn.conf -E production
nginx file here:
upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;
}
server {
listen 80;
root /home/rails/company_startup/public;
server_name _;
index index.htm index.html;
client_max_body_size 1M;
location / {
try_files $uri/index.html $uri.html $uri #app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri #app;
}
location #app {
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;
}
}
This sounds like an unicorn restart problem. You said you don't use capistrano. How do you deploy your application?
EDIT
Unicorn makes better use of resources available to you using multi-process architecture. When it starts, the worker loads the ruby environment and then spawns workers that handles the requests. The master never handles the request, always the workers.
When a worker takes too long, the master can kill it and starts a new worker again.
You seem to use 4 workers. I don't know the size of your droplet on DO, but it seems that the master can't start anymore workers. Could you tell me the size of your droplet (CPU & memory)?
I would install the unicorn-worker-killer gem and test the application again. This should restart your workers in a more effective way than the unicorn master.
EDIT 2:
If this doesn't work, could you try replacing your upstream line with this in your nginx conf file:
upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }
And this in your unicorn conf file:
listen "127.0.0.1:8080
And restart nginx then unicorn.
EDIT 3:
I think I got it
Could you please change your files like this :
unicorn.conf
listen "/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/company_startup"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"
Nginx file
upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;
}
server {
listen 80;
root /home/rails/company_startup/public;
server_name <PLEASE PUT YOUR SERVER NAME>;
index index.htm index.html;
client_max_body_size 1M;
location / {
try_files $uri/index.html $uri.html $uri #app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri #app;
}
location #app {
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;
}
}
Restart unicorn (Make sure to replace the values between <>)
kill -s QUIT $(< /var/run/unicorn.pid)
bundle exec unicorn -c <PATH TO unicorn.conf FILE> -E <RAILS ENVIRONMENT> -D
Then restart nginx
sudo service nginx restart
and see if it works.

403 error with nginx + passenger + rails 3

I have simple application which works well on Apache but gives me error 403 after moving to Nginx.
Here is my configuration:
server {
server_name myapp.com;
access_log off;
root /home/www/myapp/public;
autoindex on;
passenger_enabled on;
rails_env production;
}
Nginx is running from www-data user which has r+x permissions to all the folders on the path to the application.
Nginx is 0.8.54 and Passenver is 3.0.5.
Any ideas what can be wrong?
Obviously no reasonable errors in nginx log file (I increased logging level to maximum) and also nothing in rails log files.
You're missing the http port:
server {
listen 80;
...
}

Resources