Install Nginx from Source in Ubuntu

Hello Everyone, the very handy command to ubuntu users installing nginx, sudo apt-get install nginx, that’s it. It does install nginx on your machine, with almost all the modules usually needed by the users, super awesome. The shortcoming of this method of installing nginx is that if you want to add more modules to the nginx, you just can’t do it. Currently, nginx installed from apt-get do not support adding custom modules to it. Now when you look over internet about how to add module in nginx, it suggests you to install nginx from source. Some times it gets so much confusing, there is something, which always holds developer back to install it this way(As they already had an easy way).

So here I will show you that installing nginx from source is as easy as the apt-get(almost) and interesting as well. Lets do it,

1. Find the stable version of Nginx (http://nginx.org/download/nginx-1.10.2.tar.gz, current stable version) compatible with your custom module you need to add(if the module doesn’t support all versions of nginx) from its download page. (tar file used here)

2. open terminal

3. sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev (install the tools required to compile nginx from source)

4. sudo su (get the super user privilege).

5. mkdir nginx (create a directory named nginx{not necessarily}, all the work will be done into this directory)

6. cd nginx (get into nginx directory)

7. wget http://nginx.org/download/nginx-1.10.2.tar.gz (download your compatible version of nginx)

8. tar -xzvf nginx-1.10.2.tar.gz(extract the downloaded content)

9. cd nginx-1.10.2 (get into nginx directory)

10. ./configure (run the configure file)

11. make & make install (google to know about them at your will, I got to work for that or just run them)

12. sudo /usr/local/nginx/sbin/nginx -s stop (stop the nginx server if already running)

13. sudo /usr/local/nginx/sbin/nginx (start the nginx server)

14. enter the ip of your server, and you must be able to see the default nginx page.

So, that’s it. You have now installed your nginx from source.
Now, the commands for starting and stopping and the locations of the config files are different than /etc/nginx. The nginx files are kept in /usr/local/nginx.

Configuration file: /usr/local/nginx/conf/nginx.conf
Start server : /usr/local/nginx/sbin/nginx
Stop server: /usr/local/nginx/sbin/nginx -s stop
Reload server : /usr/local/nginx/sbin/nginx -s reload
Other commands you can find by tabbing after -s or reading the /usr/local/nginx/sbin/nginx file.

Now you can add any module to your nginx, by compiling nginx with the module. Go ahead and learn and test different great available modules of nginx. One with which I’m currently fascinated with is rtmp module.

Note.
1. Each time you are adding a module, make sure you add all other modules(which you earlier had compiled with and still need them) as well.

2. Each time after the module is added, restart the nginx i.e., stop and start, rather than reload.

Latest Comments
  1. Akash December 23, 2016
    • Satys December 23, 2016

Leave a Reply

Your email address will not be published. Required fields are marked *