Nginx passenger integration mode always require Passengerfile.json file? - ruby-on-rails

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

Related

Nginx and passenger root directive not working with Capistrano 3. Symlink to current release breaks app

When I deploy with Capistrano 3 I deploy to /home/dev/app-name/. Cap creates a directory structure /home/dev/app-name/current/
which is a symlink to /home/dev/app-name/releases/20181129161818 (the current release).
This symlink is broken and does not work for nginx and passenger. I know this because this is my app config located in /etc/nginx/conf.d/app-name.conf:
server {
listen 80;
server_name app-name.domain.com;
passenger_enabled on;
passenger_ruby /home/dev/.rvm/gems/ruby-2.5.1/wrappers/ruby;
rails_env production;
root /home/dev/app/app-name/releases/20181129161818/public/;
#root /home/dev/app/app-name/current/public;
}
if I comment out the path root /home/dev/app/mullen-admin/releases/20181129161818/public/; and sudo service nginx restart the app works.
If I use the other root directive, the app is broken and I get this 500 Server Error.
2018/11/29 15:31:43 [alert] 11278#0: *3 Cannot stat '/home/dev/app/app-name/current/passenger_wsgi.py':
Permission denied (errno=13); This error means that the Nginx worker process (PID 11278, running as UID 1002) does not have permission to access this file.
Please read this page to learn how to fix this problem: https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/?a=upon-accessing-the-web-app-nginx-reports-a-permission-denied-error;
Extra info, client: 10.194.234.100, server: app-name.domain.com, request: "GET /employees/sign_in HTTP/1.1", host: "app-name.domain.com"
I am running centos-release-7-5.1804.5.el7.centos.x86_64 on a virtual machine at the office I work at. I have a sudouser dev that I use to ssh and deploy with.
Please help!? I need the app to work at /current in the nginx root directive so I can deploy and have changes take effect.
I assume capistrano has already symlink directive: ln -nfs release_path current_path
Cannot stat '/home/dev/app/app-name/current/passenger_wsgi.py':
Permission denied (errno=13);
Your symlink is not broken, your permissions are and you must align them (passenger does not have permission to create file). Change the chmod after deploy:symlink
Something like
run "#{try_sudo} chmod 755 -R #{current_path}"
Also depending on your config you might want for example to execute chown instead of sudo

Rails/Nginx/Passenger ERROR: Phusion Passenger doesn't seem to be running

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?

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.

Rails - Nginx, Passenger is not responding

I have a problem to get rails running. I'm using nginx, passenger for first time and cannot get it working.
This site can’t be reached
I followed this tutorial on phusionpassenger, and checked 3 times. Just instead of pulling theirs demoapp I made a new one.
Ubuntu 16.04 (Xenial)
node -v = v4.8.0
ruby -v = ruby 2.4.0p0 (2016-12-24 revision 57164)
[x86_64-linux]
rails -v = Rails 5.0.2
Passenger Installation:
sudo /usr/bin/passenger-config validate-install
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... ✓
Memory Stats:
---------- Nginx processes -----------
PID PPID VMSize Private Name
--------------------------------------
28956 1 174.3 MB 0.5 MB nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
28961 28956 174.3 MB 0.6 MB nginx: worker process
### Processes: 2
### Total private dirty RSS: 1.16 MB
----- Passenger processes -----
PID VMSize Private Name
-------------------------------
28936 441.1 MB 1.2 MB Passenger watchdog
28939 654.1 MB 2.9 MB Passenger core
28945 449.3 MB 1.3 MB Passenger ust-router
### Processes: 3
### Total private dirty RSS: 5.43 MB
passenger.conf
passenger_ruby /usr/local/rvm/gems/ruby-2.4.0/wrappers/ruby;
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
added line to nginx.conf
http {
...
include /etc/nginx/passenger.conf;
...
}
nginx app setting: (quant.conf)
server {
listen 80;
server_name (AWS PUBLIC IP);
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/ubuntu/quant/public;
rails_env production;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-2.4.0/wrappers/ruby;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Thanks for any help with this.

Problem starting Passenger with Nginx

I have just setup Passenger with Nginx and it seems to install fine but when I run it I try to start it by:
passenger start -e production
I get:
=============== Phusion Passenger Standalone web server started ===============
PID file: /root/rails_apps/myapp/tmp/pids/passenger.3000.pid
Log file: /root/rails_apps/myapp/log/passenger.3000.log
Environment: production
Accessible via: http://0.0.0.0:3000/
You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
2011/04/18 07:17:27 [error] 9125#0: *4 "/root/rails_apps/myapp/public/index.html" is forbidden (13: Permission denied), client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "0.0.0.0"
and I get "Unable to connect" when I try to access my site in the browser.
Here is configuration in nginx.conf
server {
listen 80;
server_name myapp.com;
root /root/rails_apps/myapp/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
any ideas?
This error seems caused because the user of nginx cannot access the mentioned file. It can be caused not only if the /root/rails_apps/myapp/public is not have a correct permission, but even if one of the parent directories does not have that!
In your nginx.conf you can see something like:
user nginx;
http {
# blah.
}
Sometimes parameter of the user can be different. Be sure to all folder is available by this user in the path.
You can check it by sudo -Hu nginx /bin/bash -l and cat /root/rails_apps/myapp/public/index.html. Test and test it again with this command until you cannot see the content of the file.
A little explanation: with that sudo command you start a shell as an user nginx. And with cat command you can simulate the file reading.
Try this:
sudo passenger start -e production
since the path you specified is in /root (/root/rails_apps/myapp/public), nginx should have enough permissions:
user root; in nginx.conf
you should also start nginx as superuser ( sudo )
but it might be better to just move your rails app somewhere to your user directory and grant needed permissions to default nginx user 'www-data'
user www-data;

Resources