Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install Passenger as an Nginx module? Tutorial doesn't explain. #2404

Closed
shelagh-lewins-ucl opened this issue Dec 23, 2021 · 18 comments
Closed

Comments

@shelagh-lewins-ucl
Copy link

** Operating system **
RedHat 8 Linux

** Nginx version **
1.20.1

https://www.phusionpassenger.com/library/install/nginx/install_as_nginx_module.html

** Passenger version **
6.0.12

** Passenger installation method **
Static or dynamic module for Nginx

I have hit the issue that the repo to install Passenger and Nginx on RedHat 8 installs Nginx 1.14.1, which is an unacceptable regression for us: phusion/passenger_rpm_automation#18

I am therefore trying to follow the tutorial to install Passenger as a module of Nginx, and I am clearly missing something obvious, because the steps in the doc do not work.

Here's the doc I'm trying to follow:

https://www.phusionpassenger.com/docs/advanced_guides/install_and_upgrade/nginx/install_as_nginx_module.html#installing-passenger-as-a-normal-or-dynamic-nginx-module

The doc says "The value for /path-to-passenger-module can be obtained with the command:"

passenger-config --nginx-addon-dir

If I haven't installed Passenger, then of course that fails with "command not found". If I have installed Passenger, it returns this:

/opt/passenger-6.0.12/src/nginx_module

However there is no folder or file at that location and the Nginx compile fails.

I assume that I need to get or build the Passenger module, but I haven't found any instructions on where to download it, or how to build it. Can you give me some guidance how to do this, and could this information be added to the tutorial?

@CamJN
Copy link
Member

CamJN commented Dec 30, 2021

If you install passenger as per the instructions here: https://www.phusionpassenger.com/docs/tutorials/deploy_to_production/installations/oss/ownserver/ruby/standalone/ (choose red hat 8 from the dropdown) then you should have all the files available, and should be able to proceed.

@Shelagh-Lewins
Copy link

Thanks, I'll give that a try. Can this information be added to the documentation? At present the instructions to which I linked above offer no guidance.

@Shelagh-Lewins
Copy link

I installed Passenger standalone as per the documentation and still had exactly the same problem.

passenger-config --nginx-addon-dir

returns

/usr/share/passenger/ngx_http_passenger_module

but there is no file there.

ls -l /usr/share/passenger/

returns

drwxr-xr-x. 3 root root  231 Dec 31 14:56 helper-scripts
-rw-r--r--. 1 root root 3524 Nov  3 21:28 mime.types
drwxr-xr-x. 4 root root   50 Dec 31 14:56 node
-rw-r--r--. 1 root root   79 Nov  3 21:28 release.txt
drwxr-xr-x. 2 root root   24 Dec 31 14:56 standalone_default_root
drwxr-xr-x. 8 root root  112 Dec 31 14:56 templates
-rw-r--r--. 1 root root 3225 Nov  3 21:28 union_station_gateway.crt
-rw-r--r--. 1 root root 4093 Nov  3 21:28 update_check_client_cert.p12
-rw-r--r--. 1 root root 5508 Nov  3 21:28 update_check_client_cert.pem
-rw-r--r--. 1 root root  800 Nov  3 21:28 update_check_server_pubkey.pem

The Passenger install seems to be OK:

sudo /usr/bin/passenger-config validate-install

returns "Everything looks good"

passenger

returns

Phusion Passenger(R) Standalone, the easiest way to run web apps.

So I am pretty sure Passenger Standalone is installed.

I downloaded the nginx source code and tried to configure it like this:

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --add-dynamic-module=$(passenger-config --nginx-addon-dir)

The configure process ended with this error:

checking for getaddrinfo() ... found
configuring additional dynamic modules
adding module in /usr/share/passenger/ngx_http_passenger_module
./configure: error: no /usr/share/passenger/ngx_http_passenger_module/config was found

Can you suggest what might be the problem? Installing Passenger does not give me the module file, so how can I get it?

@CamJN
Copy link
Member

CamJN commented Dec 31, 2021

You're right I completely forgot that some of the sources were split off into the passenger-devel package. You need that too. I really should update the docs, as you've said.

@Shelagh-Lewins
Copy link

Thank you! I ran this:

sudo dnf install passenger-devel.x86_64

And then my .configure code as above, and then

make modules

This ran and has created the file

objs/ngx_http_passenger_module.so

That's great :)

@Shelagh-Lewins
Copy link

You're right I completely forgot that some of the sources were split off into the passenger-devel package. You need that too. I really should update the docs, as you've said.

Instead of analysing the compatibility string and trying to understand the boolean list of flags, using nginx -V seems a much easier way to find the flags with which Nginx was compiled? I found that idea here.

@CamJN
Copy link
Member

CamJN commented Dec 31, 2021

That doesn't actually always work, there are Nginx packages out there where the configure flags don't match the compatibility string.

@Shelagh-Lewins
Copy link

I must have been lucky with the flags...

It's almost working now but I am getting an Nginx error:

"/var/www/myapp/bundle/public/index.html" is not found

There is no actual folder /var/www/myapp/bundle/public but presumably Meteor does some magic with symlinks, as that was never a problem before?

I've used a copy of myapp.conf from the previous (working) version which used Nginx + Passenger. The file structure in /var/www/myapp is unchanged, so I guess there must be something different about configuring a Meteor app when using Passenger as a dynamic module? I have set passenger_enabled on but is there something else I need to do?

(With Passenger as a module, is there any way to inspect what it's doing? passenger-status says "Passenger doesn't seem to be running".)

Here's a snippet from myapp.conf, which as I say works when Nginx and Passenger are installed together.

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/myapp/bundle/public;

    # Turn on Passenger
    passenger_enabled on;

    # number of proxy servers so client ip address can be found
    passenger_env_var HTTP_FORWARDED_COUNT 1;

    # Tell Passenger that your app is a Meteor app
    passenger_app_type node;

    passenger_startup_file main.js;

Thank you for your help so far. If you have any thoughts as to what needs to be configured differently when running Passenger as a dynamic module, that would be awesome also.

@CamJN
Copy link
Member

CamJN commented Dec 31, 2021

Just some quick questions to rule out some easy to forget things: do you load_module the dynamic module you compiled? Have you restarted nginx? What does nginx -t say?

@Shelagh-Lewins
Copy link

Thanks! Yes:

/etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
load_module "/usr/share/nginx/modules/ngx_http_passenger_module.so";
include /usr/share/nginx/modules/*.conf;

...

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

And I have run:

sudo service nginx stop
sudo service nginx start

There are no errors in the log, only the "is not found" message.

@Shelagh-Lewins
Copy link

Forgive me if this is a stupid question, but you don't have to include any configuration files do you, as in a normal build? e.g.

nginx.conf

include /etc/nginx/passenger.conf

Just checking whether the dynamic module is entirely self contained or whether we need to specify things like

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;

@CamJN
Copy link
Member

CamJN commented Jan 4, 2022

Yeah all configuration must be done, just like with the compiled-in module.

@CamJN
Copy link
Member

CamJN commented Jan 4, 2022

Yes, the module just tells nginx how to talk to passenger. To find out what the crash is about, run nginx directly with nginx which should print errors to stdout. Passenger ruby is just a path to a ruby executable, and passenger root is available from passenger-config --root.

@Shelagh-Lewins
Copy link

Thank you! I have an exciting new error now that I have followed your instructions and set:

passenger_root /usr/local/share/gems/gems/passenger-6.0.12;

Nginx error.log:

App 749889 output: SpawnEnvSetupperShell: /usr/local/share/gems/gems/passenger-6.0.12/buildout/support-binaries/PassengerAgent: Permission denied
App 749889 output: SpawnEnvSetupperShell: line 0: exec: /usr/local/share/gems/gems/passenger-6.0.12/buildout/support-binaries/PassengerAgent: cannot execute: Permission denied

Permissions on PassengerAgent are:

-rwxr-xr-x. 1 root root 43749104 Jan 3 20:09 /usr/local/share/gems/gems/passenger-6.0.12/buildout/support-binaries/PassengerAgent

@CamJN
Copy link
Member

CamJN commented Jan 4, 2022

Hmm, given the permissions, I think the env setup process is running as the nobody user. Can you check the Nginx config for what user it will try to change to for workers? If there's none set or it's root, then passenger will change to nobody to reduce privileges.

@Shelagh-Lewins
Copy link

Is that worker_processes?

nginx.conf

user nginx;
worker_processes auto;

My app bundle is owned by a dedicated user, as recommended in the tutorials, but I don't know how you tell Passenger about that...in the compiled version it just works!

@Shelagh-Lewins
Copy link

Thank you so much for your patient and excellent help. I have got it working, by changing ownership of PassengerAgent, and should be OK now. (somewhere in all the messing about I had removed the passenger_ruby setting, that was the final thing to get it right). You are a hero.

@Shelagh-Lewins
Copy link

For the documentation, modern Nginx is build using --with-compat, I think? So the doc could suggest that people use nginx -V and if it was built using --with-compat, they can do:

./configure --with-compat --add-dynamic-module=$(passenger-config --nginx-addon-dir)

then I think you don't need to actually make and install nginx do you? You can do:

make modules

so you won't interfere with the system nginx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants