How to enable dynamic module with an existing NGINX installation - nginx

Introduction
From NGINX version 1.9.11 and upwarts, a new feature is introduced: dynamic modules. With dynamic modules, you can optionally load separate shared object files at runtime as modules – both third-party modules and some native NGINX modules. (source)
My setup and the problem
I have NGINX installed from the mainline (currently 1.9.14) so it is capable to use dynamic modules. It has also the module I want dynamicly enabled:
nginx -V
nginx version: nginx/1.9.14
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules ... --with-http_geoip_module=dynamic ...
Note the --with-http_geoip_module=dynamic which loads the module I need (dynamically).
Unfortunately, the documentation is lacking (some details) and I am unable to set this up.I have an existing NGINX installation (not from source). But so far as I can understand I just need to build the module, place the generated module file in the right NGINX folder and enable it in the config file.
What I tried so far
I tested this on a different machine (with the same configuration, but not a production machine), but I don't see the ngx_http_geoip_module.so file.
The commands I used:
wget http://nginx.org/download/nginx-1.9.14.tar.gz
tar -xzf nginx-1.9.14.tar.gz
cd nginx-1.9.14/
./configure --with-http_geoip_module=dynamic
The questions
Is it a problem that I try to build the module on a system that has
NGINX installed not from source?
Why is there no .so file generated by my commands?

I had the same question, and #vladiastudillo answer was the missing piece I needed.
First add the nginx stable repo:
sudo add-apt-repository ppa:nginx/stable
Then run apt update:
sudo apt-get update
And get the nginx geoip module:
sudo apt-get install nginx-module-geoip
This will download and load the module to /usr/lib/nginx/modules
To load the nginx module,
open nginx.conf:
sudo nano /etc/nginx/nginx.conf
add add below in the main context:
load_module "modules/ngx_http_geoip_module.so";
The module will be loaded, when you reload the configuration or restart nginx.
To dynamically “unload” a module, comment out or remove its load_module directive and reload the nginx configuration.

Found this to be slightly different on Amazon Linux 2016.09, Amazon Linux 2016.03 after performing yum update.
You can confirm this ahead of time by using this command on your ec2 instance sudo yum search nginx-mod-http-geoip and you will see an N/S matched: nginx-mod-http-geoip entry in the response with specifics of nginx-mod-http-geoip.x86_64 : Nginx HTTP geoip module
In these cases, the installed nginx version will be 1.10.1. When this is true, you can simple install the nginx geoip module from Amazon's existing yum repo via:
sudo yum install nginx-mod-http-geoip
Then associate the module with your nginx.conf and placing this line in the main context
include /usr/share/nginx/modules/mod-http-geoip.conf;
(note this is subtly different from the main answer - in aws you have an entry in nginx.conf pointing to another *.conf file which then points to the *.so file)

If you are using docker nginx:latest this module is already included in the image as such you only need specify load_module as such:
"/usr/lib/nginx/modules/ngx_http_geoip_module.so";
You also need to create a geoip folder in your nginx mapped volume.
Though the databases seem to no longer been updated or available and geoip2 modules are not included. So you many need to google...

I had the same issue, you have to install the http_geoip_module lib for your ubuntu version with:
$ sudo apt-get install nginx-module-geoip

Related

How do I fix 502 Bad Gateway error with GCP and NGINX

I'm trying to follow a tutorial on creating an Apache Airflow pipeline on a GCP vm instance (https://towardsdatascience.com/10-minutes-to-building-a-machine-learning-pipeline-with-apache-airflow-53cd09268977) but after building and running the docker container, I get this "502 Bad Gateway" error with Nginx 1.14 when try to access the webserver using:
http://<VM external ip>/
I'm quite new to using GCP and can't figure out how to fix this.
Some online research has suggested editing NGINX configuration files to:
keepalive_timeout 650;
keepalive_requests 10000;
But this hasn't changed anything.
The GCP instance is a N1-standard-8 with Ubuntu 18.04, and Cloud, HTTPS and HTTP access enabled.
The Nginx sites enabled are :
server {
listen 80;
location / {
proxy_pass http://0.0.0.0:8080/;
}
}
Root Cause:
The issue the you experience has nothing to do with keepalives, it is rather simpler - the docker container exits out and isn't running, so when nginx tries to proxy your request into the container, it fails and thus the error. Said failure is due to the incompatibility of airflow with current versions of sqlalchemy.
Verification:
run this command to see the logs of the failed container
sudo docker logs `sudo docker ps -a -f "ancestor=greenr-airflow" --format '{{.ID}}'`
and you will see that the python inside the container fails to import a package with the following error:
No module named 'sqlalchemy.ext.declarative.clsregistry'
Solution:
While I followed the tutorial to the letter, I'd recommend against
running commands with sudo you may want to deviate from the tutorial a
wee bit in order not to.
before running
sudo docker build -t greenr-airflow:latest .
command, edit the Dockerfile file and add the following two lines
&& pip install SQLAlchemy==1.3.23 \
&& pip install Flask-SQLAlchemy==2.4.4 \
somewhere up in the list of packages that are being installed, I've added it after
&& pip install -U pip setuptools wheel \
which is line 54 at the time of writing.
If you would like to re-use the same instance, delete and rebuild the images after making changes to the file:
sudo docker rmi greenr-airflow
sudo docker build -t greenr-airflow:latest .

multiple nginx installation on same server how to set one as default

I'm configuring an nginx server to stream using rtmp.
As I just found out I have different nginx installations.
One is located on /etc/nginx (the old one, and the one that is running by default), and other one it's on /usr/local/nginx.
I want to make a symbolic link somewhere so I can define that the server executes the one located at /usr/local
Doing some more reading, I realized that I had 2 nginx was because I installed one with apt-get and a newer version from source. I uninstalled with apt-get purge. Now what I need to find out is how to set the nginx installed from source as default system.
The nginx installed from source is up and running, but I can't do a restart by any means.
/usr/local/nginx/sbin$ sudo ./nginx -s stop
/usr/local/nginx/sbin$ sudo ./nginx
Did the trick.

Nginx not working properly after update

Okay, so I had nginx 1.4.6 running on ubuntu 13.10 without any problems.
I tried to update nginx to 1.6.0 via this url (http://leftshift.io/upgrading-nginx-to-the-latest-version-on-ubuntu-servers)
Now nginx is not running and not willing to start (no reaction at all). nginx -v gives "nginx: command not found" as a result. So looks like nginx can't be found.
I looked around here and on other sites, but wasn't able to find the solution. So, if anyone can.. plz do..
As this was a server without any active tools or software I decided to remove and reinstall nginx.
I used this answer: How can I restore /etc/nginx?
QUOTE:
To recreate it, first uninstall using purge to remove even configuration files and records:
sudo apt-get purge nginx nginx-common nginx-full
then reinstall:
sudo apt-get install nginx
After these two commands, nginx was up and running again. I can now use my backup to upload the predefined .vhosts files to sites-enabled again.

Nginx w/ Passenger support successfully installed - Nginx nowhere to be found

I am deploying a rails app using ubuntu, nginx, & passenger.
I have rails & passenger installed properly. So, I go to run:
rvmsudo passenger-install-nginx-module
This runs all the way through and tells me it was successful. However, I run nginx -v and it tells me that it is not installed. During Passenger's installation process, I specified it to use /etc/nginx instead of /opt/nginx. I can't continue with my application deployment because the following command won't work (unrecognized service)
sudo service nginx start
Wondering if anyone has encountered, or understands this issue.
If you specified /etc/nginx as prefix then your Nginx is installed in /etc/nginx/sbin/nginx. I think you meant to overwrite the system's Nginx, but that's actually not what you have done: you've only installed a completely seperate Nginx installation, into /etc/nginx. So now you have two instances:
/usr/sbin/nginx, which uses config file /etc/nginx/nginx.conf
/etc/nginx/sbin/nginx, which uses config file /etc/nginx/conf/nginx.conf
Are you on Debian or Ubuntu? If so, then the easiest way to overwrite your system's Nginx with a Phusion Passenger-enabled Nginx is not to use passenger-install-nginx-module, but to use the Debian packages provided by Phusion Passenger.

Enable nginx module on Laravel Homestead?

How can I install and enable the file upload and upload progress module on nginx with the Laravel Homestead box on Vagrant?
I believe all you need to do, like it was mentioned above, is log in with ssh to your box and install the nginx-extras package. So:
Got to your Homestead directory.
Do 'vagrant ssh'
Once in do 'sudo apt-get install nginx-extras'
Restart nginx with 'sudo service nginx restart'
Check for the module in the output of 'sudo nginx -V'. Messy but you should see 'nginx-upload-progress' somewhere near the end of the output.
You can do everything via ssh. Read more detail about using ssh in Homestead at here.

Resources