nginx with passenger - nginx

I'm trying to move from Apache + Passenger to Nginx + passenger on my Ubuntu Lucid Lynx box.
When I install passenger:
sudo gem install passenger
and
cd /var/lib/gems/1.9.1/gems/passenger-2.2.14/bin
sudo ./passenger-install-nginx-module
everything is fine (no error). Nginx is downloaded and compiled and installed at the same time (when selecting the first option during passenger installation). By default it is installed in /opt/nginx.
I end up with the configuration file /opt/nginx/conf/nginx.conf; This conf file was automatically updated with passenger config). The thing I do not understand is that I also have the configuration file /etc/nginx/nginx.conf. What is the purpose of this one when it seems that the conf file in /opt/... is the main one?
When I run /etc/init.d/nginx start, it starts correclty saying that /etc/nginx/nginx.conf is ok. Does it mean that it does not check the other conf file?
I updated /etc/init.d/nginx script and added /opt/nginx/sbin at the beginning of the PATH and it seems the correct conf file is taken into account. It seems like I have two nginx installations where I only relied on passenger to install it.

You did end up with 2 Nginx installations:
The one installed globally by your OS's package manager (/usr/sbin/nginx). This uses /etc/nginx/nginx.conf as configuration file by default.
The one installed by Phusion Passenger (/opt/nginx/sbin/nginx). This uses /opt/nginx/conf/nginx.conf as configuration file by default.
Only (2) has Phusion Passenger support. Ignore (1) and do not use it.

I don't think that this is a programming related question, but anyway...
It seems like passenger installation have configured nginx to look for config file in /etc/nginx. Post your nginx configure flags and check if /etc/init.d/nginx overrides config file path.
http://wiki.nginx.org/NginxCommandLine

Related

Will reinstalling nginx remove configs

I want to add a new module to nginx but its on production and deleting nginx configuration is not an option.
After a bit of research I noticed that I have to reinstall nginx in order to add a module to it.
So my question is, is it possible in any way to reinstall nginx (and executing the ./configure command without messing up the current nginx configuration?
All I need is to generate the .so file to copy it to the existing /usr/lib64/nginx/modules directory.

How to install a module on nginx?

When running nginx -t I get this error:
nginx: [emerg] unknown directive "subs_filter_types" in /etc/nginx/sites-enabled/my.site.com.conf:285
nginx: configuration file /etc/nginx/nginx.conf test failed
So I need to install the substitution filter module and in the nginx documentation https://www.nginx.com/resources/wiki/modules/substitutions/#subs-filter-types
Which says to run these commands:
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
./configure --add-module=/path/to/module
The problem is I don't have the configure script anywhere in my nginx installation nor in the
git repository. I really don't understand.
At the very least I want to know the content of that nginx configure script.
The instructions you are referring to are for compiled installation.
Assuming you want to add the module to your existing NGINX install, below are the generic steps that will get things running.
Fetch exactly matching version of NGINX as the one you have installed, from nginx.org onto your system and extract it to, say, /usr/local/src/nginx
git clone NGINX module's source code onto your system, to e.g. /usr/local/src/nginx-module-foo
cd /usr/local/src/nginx. This is where you will find the configure script. You will basically configure NGINX with the location of the config of specific module in question, thus next step:
./configure --add-dynamic-module=../nginx-module-foo --with-compat
make
As a resulf of the compilation you will have module's .so file somewhere in objs directory of your NGINX sources. You will then copy it over to e.g. /usr/lib64/nginx/modules/ directory.
To make your existing NGINX load the module, add load_module modules/foo.so; at the very top of /etc/nginx/nginx.conf.
You can decipher the many downsides to the whole compiled approach: one is having compilation software (gcc) on a production system, other is having to re-do all those steps any time you upgrade NGINX or the module.
For the reasons mentioned, you might want to search for a packaged install of third-party modules.
For CentOS/RHEL systems, you might want to look at GetPageSpeed repos (subscription-ware, and I'm biased to mention it, because I'm the maintainer. But this is free for CentOS/RHEL 8 at the time of this writing. Installing the module you want, goes down to a couple of commands:
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-substitutions
For Debian-based systems, probably there are alternative PPAs existing for the same.
Just replace prefix subs with sub.
For default nginx 1.10.3 installation (Ubuntu 16.04.5 LTS)
nginx -V should have flag --with-http_sub_module to use sub_* directives.
Usage example:
sub_filter_types text/html text/css text/xml;
sub_filter 'needle' 'replacement';
sub_filter_once off;
NGINX documentation link

Nginx PageSpeed Module on Nginx from PhussionPassenger APT

I have installed nginx/1.12.1 and Phusion Passenger by APT from https://oss-binaries.phusionpassenger.com repository. It's configured correctly within my Rails apps.
Thereafter, I want to improve nginx by adding nginx pagespeed module dynamically following this https://www.modpagespeed.com/doc/build_ngx_pagespeed_from_source to build ngx_pagespeed module and following this https://www.nginx.com/blog/compiling-dynamic-modules-nginx-plus/ to compile dynamic module, by running :
$ ./configure --with-compat --add-dynamic-module=$HOME/ngx_pagespeed-${NPS_VERSION} ${PS_NGX_EXTRA_FLAGS}
$ make modules
After that, I copied ngx_pagespeed.so from objs/ folder into /etc/nginx/modules and of course loading the module into nginx.conf by adding load_module modules/ngx_pagespeed.so; on it. But when I reload nginx it's reproduced following error:
nginx: [emerg] module "/usr/share/nginx/modules/ngx_pagespeed.so" is not binary compatible in /etc/nginx/nginx.conf:5
My question is:
How do I add ngx_pagespeed module on nginx from PhusionPassenger APT?
What is the right ./configure flags for compiling additional module without forgetting previous installed nginx (from PhusionPassenger APT) modules?
Thank you
On ubuntu xenial, you'll have an easier time adding your configure flags to the passenger-install-nginx-module script like so: passenger-install-nginx-module --extra-configure-flags="--with-compat --add-dynamic-module=$HOME/ngx_pagespeed-${NPS_VERSION} ${PS_NGX_EXTRA_FLAGS}" instead of using the nginx-extras package, as matching the flags from the packaging process at phusion is a pain. You can read more about it here: https://www.phusionpassenger.com/library/install/nginx/customizing_compilation_process.html

Best way to verify that passenger nginx module has been successfully compiled?

I have several servers chef managed each running a stack with:
nginx
phusion passenger
I'd like to make the passenger gem upgrade process automated with the ability to conditionally skip passenger nginx module compilation meaning I don't want the compile process to happen on every chef run, only on runs where it is determined that it is necessary (typically because passenger gem version is being upgraded, but also in cases where the passenger gem is not being upgraded but the compilation failed previously).
Currently I check the version of passenger being run, but in cases where the gem actually installs to the correct version but the compilation fails, that idempotency check is too broad and I fail to get a compile attempt when I need one.
What is the most accurate way to verify that the passenger nginx module has been compiled? Is there a specific file in a stable location whose existence I can check for?
Right now my chef block looks like this:
execute "compile passenger nginx module" do
ruby_vers = node[:ruby][:global_version]
passenger_vers = node[:passenger][:version]
ruby_parent_vers = node[:ruby_parent_vers]
command "export ORIG_PATH=\"$PATH\"; sudo -s -E; export PATH=\"$ORIG_PATH\"; /usr/bin/ruby /usr/lib/ruby/gems/2.4.0/gems/passenger-#{passenger_vers}/bin/passenger-install-nginx-module --auto --auto-download"
# check for a difference between passenger version requested and passenger version running
not_if { `passenger --version` == cur_vers }
end
Have you tried passenger-config about compiled?

Setting up Tornado with Nginx on Ubuntu 10.04 for production use

I understand that there's an nginx configuration file at http://www.friendfeed.com
But i don't really know how to set up Tornada for production use on Ubuntu 10.04 with Nginx.
Here's my situation and assumptions:
1) Assuming my Tornado project is set up as such:
project/
src/
static/
templates/
project.py
And I have installed Tornado by downloading the repositary from Github and than sudo python setup.py install
2) I've installed Nginx and started it based on the instructions here : http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid
My questions are:
Where does my nginx configuration file go ? Within the src/ folder?
After configuring Nginx, how do I start my Tornado project?
This could help a lot: https://github.com/chaselee/tornado-linode
Check out the link in the Readme to see how to deploy in production on Ubuntu 10.04.
Basically I keep the nginx conf in my repo, which gets pulled into the server, and the conf file is symlinked into the actual nginx directory where it needs to go.
For an EC2 Ubuntu with a default install the config file is here:
/etc/nginx/nginx.conf
I would recommend symlinking it like chaselee suggested

Resources