Install Nginx Web Server on Ubuntu. Terminal commands to install Nginx 1.9.6 on Ubuntu 15.10, Ubuntu 14.04 and Derivatives. NGINX is a high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.
NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. In simple words, Nginx is a web server with a strong focus on performance and low memory usage. NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. Nginx supports HTTP/2, massive performance and security enhancements, greater visibility into application health, and more. NGINX powers several high-visibility sites, such as Netflix, Hulu, Pinterest, CloudFlare, Airbnb, WordPress.com, GitHub, SoundCloud, Zynga, Eventbrite, Zappos, Media Temple, Heroku, RightScale, Engine Yard, MaxCDN and many others.
Install Nginx Web Server on Ubuntu
Nginx 1.9.6 is the latest version of Nginx Web Server. Nginx 1.9.6 has been released with the following changes:
- Bugfix: a segmentation fault might occur in a worker process when using HTTP/2.
- Bugfix: the $server_protocol variable was empty when using HTTP/2.
- Bugfix: backend SSL connections in the stream module might be timed out unexpectedly.
- Bugfix: a segmentation fault might occur in a worker process if different ssl_session_cache settings were used in different virtual servers.
- Bugfix: nginx/Windows could not be built with MinGW gcc; the bug had appeared in 1.9.4.
- Bugfix: time was not updated when the timer_resolution directive was used on Windows.
- Miscellaneous minor fixes and improvements.
Download Nginx Sources
There are currently two versions of NGINX available: stable (1.8.x), mainline (1.9.x). In general, the stable release is recommended, but the mainline release is typically quite stable as well.
Source code repository is at hg.nginx.org/nginx. Older versions can be found here. By default, NGINX will be installed in /usr/local/nginx
Install Nginx Web Server on Ubuntu
Method 1 – CLI
Nginx Web Server can be installed on Ubuntu by running the following command in Terminal:
$ sudo apt-get update
$ sudo apt-get install nginx
Method 2 – Nginx Ubuntu PPA
The Nginx Ubuntu PPA is maintained by volunteers and is not distributed by nginx.org. It has some additional compiled-in modules and may be more fitting for your environment. You can get the latest stable version of NGINX from the NGINX PPA on Launchpad: You will need to have root privileges to perform the following commands.
For Ubuntu 10.04 and newer:
sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update
apt-get install nginx
If you get an error about add-apt-repository not existing, you will want to install python-software-properties.
Once installed, run the following command to check if the Nginx installation was successful. You can check the installation status by viewing Nginx page via web browser using server IP Address. To know the Server IP address, run the ip command given below.
$ ip addr show
Now copy the Server IP Address and open it in the web browser. Paste the Server IP Address in the URL box “http://server-ip-address”. If the Nginx installation is successful, you will see the default Nginx page:
Starting, Stopping, and Restarting NGINX
To stop Nginx web server:
$ sudo service nginx stop
To start the Nginx web server:
$ sudo service nginx start
To stop and then start the Nginx web server service again:
$ sudo service nginx restart
Make Nginx web server restart automatically when the server is rebooted:
$ sudo update-rc.d nginx defaults
Options
Below are the command line options:
- -?, -h Print help.
- -v Print version.
- -V Print NGINX version, compiler version and configure parameters.
- -t Don’t run, just test the configuration file. NGINX checks configuration for correct syntax and then try to open files referred in configuration.
- -q Suppress non-error messages during configuration testing.
- -s signal Send signal to a master process: stop, quit, reopen, reload. (version >= 0.7.53)
- -p prefix Set prefix path (default: /usr/local/nginx/). (version >= 0.7.53)
- -c filename Specify which configuration file NGINX should use instead of the default.
- -g directives Set global directives. (version >= 0.7.4)