What is Nginx? How to Install and configure Nginx Web Server

Nginx is one of the popular Web Server, used in many Web server systems in the world. The website vinasupport.com itself is also using Nginx as a Web server.

what is nginx

This article will introduce, detailed instructions for installing on Linux,  configuring,  config and using Nginx.

What is Nginx?

Nginx is a lightweight, powerful Web Server and uses a single-threaded, event-driven architecture so it uses resources more reasonably than Apache Server. Therefore it is commonly used for tasks such as Load Balancing, HTTP caching, or as a Reverse Proxy.

  • Author: Igor Sysoev
  • Developed by Nginx, Inc.
  • First released on October 4, 2004
  • Stable version: 1.16.1 (August 13, 2019) at the time of this writing
  • Repository: hg.nginx.org/nginx
  • Programming language: C
  • OS: BSD variant, HP-UX, IBM AIX, Linux, macOS, Solaris, Windows
  • Software type: Web server, reverse/mail proxy server
  • Website: nginx.org

Features of Nginx

  • Capable of handling over 10,000 concurrent connections with low memory
  • Serves static files (static files) and indexes files
  • Accelerate reverse proxy with cache (cache); Simple load balancing and fault tolerance
  • Accelerated support with caching of FastCGI, uwsgi, SCGI, and Memcached servers
  • Modular architecture; Increase page loading speed with automatic gzip compression
  • Support SSL and TLS encryption
  • Flexible configuration; Save the query log
  • Redirect error 3XX-5XX
  • Rewrite URL (URL rewriting) uses regular expressions
  • Limit query response rate
  • Limit the number of simultaneous connections or queries from 1 address
  • Ability to embed PERL code
  • Support and compatible with IPv6
  • Support WebSockets
  • Supports FLV and MP4 file transfer

Outstanding advantages of Nginx over Apache

Apache waits for a complete connection to make another connection sequentially. But Nginx allows concatenating multiple queries simultaneously. This is extremely significant for busy sites, large traffic.

Apache uses more memory resources, while Nginx can run on VPS with a minimum RAM of about 500M which is already running very well. Nginx is easier to configure and understand than Apache using the “.htaccess” file. Also, Apache’s “.ht *” file is also recommended to be much slower!

Install Nginx Web Server

To install Nginx Web Server use the following command:

# On CentOS / RHEL / Fedora

sudo yum install -y nginx

# On Ubuntu / Debian / LinuxMint

sudo apt install -y nginx

Boot and allow booting when booting the oper

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Check if Service is working.

sudo systemctl status nginx.service

By default, the firewall on HDH will block port 80 of Nginx, to open the port we use the following command:

# On CentOS / RHEL / Fedora

sudo firewall-cmd –zone = public –add-port = 80 / tcp –permanent
sudo firewall-cmd –reload

# On Ubuntu / Debian / LinuxMint

sudo ufw allow ‘Nginx Full’

Open the browser and access with the link http: // <Hostname or IP Address> and display the ” Test Page ” of Nginx, we have successfully installed.

nginx test page

The commands needed to manage

Check the configuration file syntax

sudo nginx -t

Reload the configuration file

sudo nginx -s reload

Open the log file
sudo nginx -s reopen

Configure Nginx Web Server

List of important files and folders

  • /etc/nginx/nginx.conf : Main config file
  • /etc/nginx/conf.d: The directory containing your own config files
  • / etc / nginx / sites-available: The directory contains the VirtualHost config files, allowing us to configure each site separately.
  • / etc / nginx / sites-available / default: The default Virtual Hosts config file

Configure Virtual Hosts

To configure Virtual Hosts, please refer to the article written very detailed here:  Instructions for configuring Virtual Hosts on Nginx

Configuration Log

Normally, Nginx’s log is stored in / var / log / nginx, which consists of two files:

  • access.log: Save access information to the Web Server
  • error.log: Save the error information

To change the path of these 2 files, we fix 2 parameters: error_log and access_log in /etc/nginx/nginx.conf :

http {
# Logging Settings
access_log /var/log/nginx/access.log ;
error_log /var/log/nginx/error.log ;

You can add these two parameters to the virtual host configuration to set separate log file paths for each website.

Configure gzip

Gzip is a method of compressing the data returned by the server, reducing the download time from the server to the client.

To enable gzip on Nginx we edit the config file  /etc/nginx/nginx.conf

http {
# Gzip Settings
gzip on ;
gzip_vary on ;
gzip_proxied any ;
gzip_comp_level 6 ;
gzip_buffers 16 8 k ;
gzip_http_version 1.1 ;
gzip_types text / plain text / css application / json application / javascript text / xml application / xml application / xml + rss text / javascript ;

Good luck to you!

You May Also Like
About the Author: Anh
Blogger at Kinghostcoupon.com

Leave a Reply

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