Rather a simple question I believe, is it possible to install passenger when nginx is already installed on your webserver?
If the answer is Yes, I already performed these actions:
At this very moment I already have nginx installed (for my PHP applications) and next I did a checkout of the passenger's git repository:
mkdir /repositories
cd /repositories/
git clone https://github.com/FooBarWidget/passenger.git
cd passenger/
and then add this snippet to /etc/nginx/conf/nginx.conf
http {
...
passenger_root /repositories/passenger;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby;
...
}
However when I want to restart nginx I get the following error:
* Starting Web Server nginx
nginx: [emerg] unknown directive "passenger_root" in /etc/nginx/nginx.conf:19
Which concludes me to say that there is still some config I need to set, for nginx to be aware that we're using passenger.
My server block
server {
listen 80;
server_name rails.kreatude.com;
root /srv/www/my_test_app;
passenger_enabled on;
}
I think your problem is that the passenger module is not present in nginx.
All the passenger dependent directives you've described (passenger_root, passenger_ruby, passenger_enabled) are available only when the passenger module is attached to nginx. This is why you have to compile nginx with --add-module='/path/to/passenger-3.0.9/ext/nginx'.
Unfortunately, I don't know of any method to enable passenger module without re-installing nginx. But, according to http://wiki.nginx.org/Modules, "Nginx modules must be selected at compile-time.", so there could be a chance that there isn't a way to do that.
In Passenger docs the chapter "Generic installation, upgrade and downgrade method: via RubyGems" discusses this. Basically, once the Passenger gem is installed, nginx needs to be recompiled (and then used instead of the yum/apt-get-installed nginx if one exists). Passenger's compilation/configuration utility "passenger-install-nginx-module" does it for you (it's part of the Passenger gem), and it automatically includes the necessary switches for Passenger. It also gives you the option to add your own switches (such as for extra modules, or to enable/disable NGiNX's built-in features).
With rvm, you could do this simply by running rvmsudo passenger-install-nginx-module.
For more detail: https://www.digitalocean.com/community/tutorials/how-to-install-rails-and-nginx-with-passenger-on-ubuntu.
I confirm ion-br's answer, I'm facing the same kind of problems and PhusionPassenger's site states:
Before you begin, you should know that installing Passenger in its Nginx integration mode involves extending Nginx with code from Passenger. However, Nginx does not support loadable modules. This means that in order to install Passenger's Nginx integration mode, it is necessary to recompile Nginx from source.
The only solution is thus to properly reinstall Nginx, if your machine is an AWS AMI instance the solution lies here.
There is a way install nginx passenger module without reinstalling/recompiling nginx
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/bionic/install_passenger.html
passenger_enabled on; in server, http, or location block.
http://modrails.com/documentation/Users%20guide%20Nginx.html#_important_deployment_options
Related
I've done a new install of nginx 1.6.3 and passenger 5.0.15 on Ubuntu 14.04 from source in order to add tracing components from AppNeta for my ROR 4.2 app on one of my servers. Nginx and passenger are running and serving pages. I am getting the trace data for server monitoring. All seems well,
However, when I run "passenger-status" (as root), I get the following:
ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it is running, then the causes of this problem could be:
You customized the instance registry directory using Apache's PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir option, or Phusion Passenger Standalone's --instance-registry-dir command line argument. If so, please set the environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory and run passenger-status again.
The instance directory has been removed by an operating system background service. Please set a different instance registry directory using Apache's PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir option, or Phusion Passenger Standalone's --instance-registry-dir command line argument.
The problem with this is that it seems to be blocking capistrano deploys; this same error is displayed by cap before exiting.
Passenger is running (it's in the ps output and pages are being served). I just need to tell passenger-status where to find the current running instance. (This is from the Design and Architecture documentation.) Therefore, it seems that setting this instance registry directory value is the required step. But to what value?
According to the Nginx Reference, the defaults are /tmp and /var/run/passenger-instreg And I've found an instance directory in /tmp. So, I've tried setting the PASSENGER_INSTANCE_REGISTRY_DIR to a number of different values:
/tmp
/tmp/passenger.JxmCeiA (the current instance directory, but this changes with each startup of Nginx)
I've even tried creating a directory at /run/passenger, setting that value in the nginx configuration file and restarting nginx. The temporary directory is being created, but passenger-status still gives the same message. Even if I use the /opt/passenger-5.0.15/bin/passenger-status script to make sure I'm using the latest version of that script.
There are some configuration values in the original 'location.ini' directory for passenger, but none were the instance registry directory, so there was nothing to reuse.
Interestingly, the /opt/passenger-5.0.15/lib/phusion_passenger/nginx/config_options.rb file does not have an entry for passenger_instance_registory_dir. It has other nginx configuration options, I would have expected it to have this one as well.
I've tried setting the environment variable as well as the Nginx passenger_instance_registry_dir option, but I must be missing something in my understanding because I can't seem to connect the passenger-status command with the current running instance.
Any help would be greatly appreciated.
Passenger author here.
/tmp/passenger.JxmCeiA is an example of an instance directory. This changes indeed with every startup (because it is specific to an instance).
The parent directory (the directory in which instance directories are located) is the instance registry directory. So in your case, the instance registry directory that is being used is /tmp.
I'm guessing that you have some kind of Passenger installation version mismatch. We've changed the structure of the instance directory a few times in the past, and every time we did this we bump an internal version number to indicate that it's incompatible with previous Passenger versions. Can you double check the following?
Does Passenger appear to be otherwise running correctly?
What Passenger version is compiled inside Nginx?
What is your passenger_root set to? Does it match the Passenger version compiled inside Nginx?
Where is the full path to the first passenger-status in PATH? Does it match passenger_root?
You also seem to be mixing the Phusion Passenger APT repository with source tarball install. Having multiple installations around is generally a bad idea. Try cleaning up your other installs so that you only end up with one.
Also check whether you are setting the PASSENGER_INSTANCE_REGISTRY_DIR environment variable correctly. Note that sudo nukes environment variables, so you need to run passenger-status like this:
# Correct:
sudo env PASSENGER_INSTANCE_REGISTRY_DIR=/tmp passenger-status
# Incorrect, sudo nukes environment variables
export PASSENGER_INSTANCE_REGISTRY_DIR=/tmp
sudo passenger-status
Regarding lib/phusion_passenger/nginx/config_options.rb: that file mainly lists per-server and per-location config options. Many config options in the main context are either not yet ported to the config_options.rb system, or not possible because they require custom attention. At present, passenger_instance_registry_dir is implemented in ext/common/nginx/Configuration.c. As we continue to cleanup and refactor the codebase, this option may eventually be moved to config_options.rb.
In case anyone else is having this problem when starting Passenger using a systemd service, this might be due to systemd's private /tmp. The problem was solved by adding PrivateTmp=false to the service file.
Source
step one check phusion passenger is installed correctly
sudo passenger-config validate-install
"if you see an ouput saying, 'Everything is looks good :-)'" then you are fine, if not you need to reinstall phusion passenger, refer to https://www.phusionpassenger.com/library/walkthroughs/start/
step two check the phusion passenger memory status
sudo passenger-memory-stats
"if you see processes running, then that's good, if not you either have to start some passenger app, or install nginx or apache with extra library for them. For nginx you need nginx and the nginx-extras".
step three uncomment the passenger_root in the nginx.conf file (for ubuntu it's usually /etc/nginx/nginx.conf) or the apache.conf file
restart nginx or apache
sudo service nginx restart # (or systemctl restart nginx, for new version of linux such as ubuntu 15.04, CentOS7)
now you can run
passenger-status
the error should go away now. The mostly likely output you will get is saying "Phusion Passenger is currently not serving any applications."
I'm running Passenger in Nginx integration mode, on Ubuntu 20.04 and I've installed it via apt from the official repos.
What worked for me was adding this to /etc/nginx/conf.d/mod-http-passenger.conf :
passenger_instance_registry_dir /tmp;
Restarting passenger the Capistrano way from the command line should now work:
$ passenger-config restart-app <your_app's_root_path> --ignore-app-not-running
If this works, Capistrano deployments should now work again.
I am really struggling to understand this.
I have used PHP / Apache all my life but I just need to have a very basic setup of a Ruby on Rails app on an Nginx server for development.
I have set up an Ubuntu 12.04 server with Vagrant / VirtualBox.
I can see in the web browser the "Welcome to nginx!" message and there's a Ruby on Rails app installed on the server (tested with someone else and working on there server).
The Ruby on Rails application is in an /app/ folder and with these folders:
- assets
- controllers
- helpers
- mailers
- models
- observers
- uploaders
- views
Now, all I need to do is run the thing. Where is my index file?
Are there any other folders I should take note of? There's nothing I can see.
I've tried configuring sites-enabled but none of it makes sense. Surely it should be a simple case of getting my-domain.com to display the index file. Simple, surely? Which file in the /app/ folder am I trying to run?
For development you can use the built-in web-server with rails s in your project folder. It will runs your RoR app on 0.0.0.0:3000. Port can be changed with -p (rails s -p 80).
Read this guide to running rails on nginx using passenger:
Once Ruby on Rails is installed, go ahead and install passenger.
gem install passenger
...
Set the root to the public directory of your new rails project. Your
config should then look something like this:
server {
listen 80;
server_name example.com;
passenger_enabled on;
root /var/www/my_awesome_rails_app/public;
}
(Don't forget the /public after the rails root location!)
I know there are about 100 questions about this, but after hours of research, I couldn't find my solution. Here's my nginx config:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/LucyRb/public;
passenger_enabled on;
passenger_app_env production;
index index.html index.htm;
server_name <domain name>;
location / {
try_files $uri $uri/ /index.html;
passenger_enabled on;
}
}
My /public directiory:
root#Lucy:/var/www/LucyRb/public# namei -l *
f: 404.html
-rwxrwxrwx root root 404.html
f: 422.html
-rwxrwxrwx root root 422.html
f: 500.html
-rwxrwxrwx root root 500.html
f: favicon.ico
-rwxrwxrwx root root favicon.ico
f: robots.txt
-rwxrwxrwx root root robots.txt
I don't think it's a permission problem. I've already run rake db:migrate to create the database, and it worked. I'm pretty sure environments are set up properly. All I get is a file listing (since autoindex is on, otherwise I get a 403). But routes, nor does the app default index/root, work. I've read the Passenger documentation, and I tried troubleshooting with the docs and other SO questions, but I can't seem to get this working.
I haven't forgotten to bundle install and all the proper packages are installed, I'm pretty sure (did I forget any? mysql, rvm and its relevant steps for installing rails, nginx, passenger... Probably another 2-3).
I know I'm not supposed to start rails server because it will only allow 1 connection at a time. So nginx is supposed to do that properly, right? Or is that what I'm supposed to do with certain flags?
Thanks in advance.
Okay everyone. With the assistance of Passenger's author on their IRC channel, I was able to resolve the problem.
I had passenger installed twice.
From articles I followed that didn't cover the topic thoroughly enough, I was under the assumption Passenger is an installable module of Nginx, which caused me to install Nginx with apt-get, and Passenger via the gems.
This is an unnecessary redundancy and causes conflicts.
Either use only apt-get or only the gems in these cases.
passenger-install-nginx-module not only installs a module, it also compiles Nginx from scratch, simply because Nginx is not a modulable application. It is either compiled alongside the module, or doesn't have one at all.
To sum it up:
Only use one method to install Nginx && passenger.
Make sure the config points to the right files.
I also had a problem with the paths to ruby. Make sure it points to the wrapper, and not the executable alone:
root#Lucy:/usr/local/rvm# which ruby
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby
In your config:
passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby;
Suggestion-
Try moving your app to someplace that is accessible by normal user.for example home directory
How did you install passenger? With RVM? RVMSUDO or sudo? Chances are you shouldn't be using your app as root. So the permissions on the files aren't allowing passenger to use the rails app.
Assuming your config.ru is in your specified passenger_app_root, try removing your location / {...} directive, restart nginx, and see if your app at least starts up. I'm not saying this is the fix, but a troubleshooting measure.
I was going to place this in my comments section but space and formatting are limited so:
I also see you're specifying passenger_enabled twice, which seems unnecessary. I've never seen it turned on in a location directive before, but that might not be your problem.
What do your logs say? You don't seem to have passenger logging/debugging turned on (in http directive):
http {
...
passenger_debug_log_file '/path/to/passenger_debug.log';
passenger_log_level 5; # default
}
Another thing I'm noticing from your post is that your public directory doesn't seem to contain a rails application??
You have
# nginx config
root /home/LucyRb/public;
# shell
/var/www/LucyRb/public
Do you have a correct app in /home/LucyRb? If so, what is the relevance of /var/www/LucyRb? If this is a mistake in your config, then it if probably going to cause some trouble!
Have you tried to change your files to www-data user?
Every time I've received that error it's been because Nginx wasn't correctly pointing to the passenger gem and executable. Here's what I suggest, to get things working:
Uninstall and/or shut down whatever nginx you've currently got installed.
cd into your app's root directory,
execute the command: passenger-install-nginx-module and let passenger download, compile, and install nginx in /opt.
use the sample config provided by the passenger script for /opt/nginx/conf/nginx.conf.
To get the server to start on boot, just add the one line /opt/nginx/sbin/nginx to your /etc/rc.local script.
This recipe has been repeatable and foolproof for me running RVM + Ruby 1.9, 2.0, and Rails 3 and 4 on Ubuntu 10 and 12.
I want to put redmine (listening on localhost:3000 standalone passenger) behind nginx, serving from http://domain.com/redmine with this simple nginx config:
server {
location /redmine/ {
proxy_pass http://domain.com:3000/;
}
}
I rewrote redmine's config/environments.rb based on the instructions from this HOWTO, and redmine properly rewrites static asset URLs, but controller URLS are not rewritten, for ex. settings point to http://domain.com/settings instead of http://domain.com/redmine/settings.
How can I properly configure redmine to run behind nginx?
This is a pretty complicated thing to do. You wouldn't think so but it is. Every single redmine version that comes out has a different set of correct and incorrect ways of accomplishing this. For example, I have a working configuration with (nginx-1.4.1, unicorn, redmine-2.2.1) but now that I'm using (nginx-1.4.2, unicorn, redmine-2.3.3) that doesn't seem to work anymore. Here's some links that may be of use:
http://www.redmine.org/issues/11881
http://www.redmine.org/issues/12102
I think I've read every question and answer on SO related to passenger/nginx and 403 errors, but none have lead me to a solution, so here I go...
I had Nginx (1.0.6) with Passenger (3.0.9) running beautifully for a rails app for many, many months with no real issues. Tonight I decided to upgrade from Passenger v3.0.9 to v3.0.12 to take advantage of a new feature. After running the install according to the provided instructions (using RVM), I went to the URL served by my rails app and got the dreaded 403 error. The nginx log file first had me thinking it was a permissions error:
directory index of "/home/SimfoUsers/public/" is forbidden, client: , server: , request: "GET / HTTP/1.1", host: ""
But after checking every possible permission, I no longer think that is the issue. I think the problem is actually that passenger is somehow not actually running, and the page is being served as a "normal" webpage by nginx. This is supported by the fact that if I add an index.html file to my rails public directory (/home/SimfoUsers/public/), nginx serves up this file as one would expect. Also, if I run passenger-memory-stats, ZERO passenger processes are running. Shouldn't nginx automatically spawn passenger processes whenever needed, or am I completely missing something here?
Here are the relevant parts of my nginx.conf file:
http {
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p290#Simfo/gems/passenger-3.0.12;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p290#Simfo/ruby;
...
server {
listen 80;
server_name simfo.info www.simfo.info;
root /home/SimfoUsers/public;
passenger_enabled on;
}
}
Basically the only thing that I changed from my previously working config file is to update the passenger_root and passenger_ruby directives to reflect the new version of passenger (3.0.12). So if this is a config file issue, I'm really at a loss to understand it...
I'm not sure whether to just delete this question, or leave it in case it can save someone else the same frustration. This definitely is a face palm moment...
In desperation, I finally rebooted the server. After that, everything worked fine. It seems that at some point the passenger-related processes died and were not re-spawned automatically. One would think that after a fresh installation and reboot of nginx, passenger would be restarted, but apparentally this is not the case. My only advice to anyone having a similar problem is to issue a ps aux | grep passenger (or tasklist on Windows?). You should see one or two processes related to passenger. If not, then something strange is going on, and a reboot might help you as well.