What is Nginx?
According to Wiki, Nginx is an open source web server which can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. Nginx claims to run 60% of the busiest website on the internet.
We use Nginx mostly as a web server(with the passenger for Rails or golang application) and as a load balancer.
How to install Nginx in Ubuntu?
Two ways to install Nginx one is from the package and other is from source(recommended)
-
Installing from the package is very simple. This will install the latest stable version
$ sudo apt-get install nginx $ sudo nginx -v nginx version: nginx/1.10.2
-
Installing Nginx from source. There are few dependencies we need to install before installing Nginx
$ sudo apt-get install libpcre3-dev build-essential libssl-dev
- libpcre3-dev -> This is basically a regular expression library
- libssl-dev -> This package is part of OpenSSL implementation of the SSL and TLS for a secure connection
- build-essentail -> This package includes GNU C++ compiler, GNU C compiler and other libraries
You can install on any preferred location, mostly it's installed in /opt or /etc
$ cd /etc/
$ sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz
Unzipping the tar file
$ sudo tar -zxvf nginx-1.10.2.tar.gz
$ cd /etc/nginx-1.10.2
Configure the build
$ sudo ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/etc/nginx"
nginx binary file: "/etc/nginx/sbin/nginx"
nginx modules path: "/etc/nginx/modules"
nginx configuration prefix: "/etc/nginx/conf"
nginx configuration file: "/etc/nginx/conf/nginx.conf"
nginx pid file: "/etc/nginx/logs/nginx.pid"
nginx error log file: "/etc/nginx/logs/error.log"
nginx http access log file: "/etc/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
Let's build and install with the above configuration
$ sudo make
$ sudo make install
We need to create a separate user and group for Nginx
$ sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
Installing from source does not include init file for starting and stop the Nginx during the server reboots
$ sudo vi /etc/init.d/nginx
Make the above file executable and add it to default run levels
$ sudo chmod +x /etc/init.d/nginx
$ sudo /usr/sbin/update-rc.d -f nginx defaults
Now we can start, stop, restart and check status using the below command
$ sudo service nginx <command>
command -> start, stop, restart, status
You can check if nginx is running using the below command or by visiting the ip address where you have installed
$ ps aux | grep nginx
Congratulation! You have successfully installed Nginx.
Part II will be about, what different files inside the conf folder does, configuring Nginx to serve an application and what's the role of each block inside nginx.conf file.
Top comments (0)