What Is NGINX? How to Install and Configure Nginx on linux system?

nginx-configuration

Nginx (pronounced “engine-x”) is a high-performance, open-source web server and reverse proxy server software. It is known for its efficiency in handling concurrent connections and its ability to serve static content quickly. Nginx is often used as a front-end web server, reverse proxy, and load balancer.

Nginx is widely used by web developers, administrators, and organizations to build scalable and high-performance web infrastructure. It can be used as a standalone web server or combined with other software to create a complete web hosting solution.

Key Features of Nginx:

  • High Performance.
  • Reverse Proxy.
  • Load Balancing.
  • Static Content Serving
  • HTTP and HTTPS Support:
  • Easy setup.

Installation and Configuration on Linux System(Ubuntu OS.) The installation process can vary depending on your operating system. Here’s a basic example for Ubuntu OS.

Step 01.

sudo apt update -y
sudo apt install nginx -y

Installation Completed. Now cross verify whether nginx installation completed or not.

Check if the service is running or not.

systemctl status nginx.service 

service nginx status

If status is Active: active (running) Then access Server/System IP on the web browser and enjoy.

Nginx Process Handling:

To start the Nginx service, you run following command:

sudo systemctl start nginx

To stop the Nginx service, useĀ  following command:

sudo systemctl stop nginx

To restart Nginx after making changes to the configuration or for any other reason, you can use:

sudo systemctl restart nginx

Configuration Testing:

Take a moment to review the configuration for any syntax mistakes before restarting or reloading Nginx. Use the given command.

sudo nginx -t

To implement changes without interfering with running connections, reload the configuration rather than restarting the entire Nginx process. Make use of the subsequent command:

sudo nginx -s reload
sudo systemctl reload nginx

Configuration File:

The main Nginx configuration file is usually located at /etc/nginx/nginx.conf.

Basic configuration of nginx.conf file:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}

http {
	sendfile on;
	tcp_nopush on;
	types_hash_max_size 2048;
	server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;


	ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

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

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}

Nginx Virtual Host Configuration file – /etc/nginx/sites-available/domain.conf

Basic configuration of virtual host file:-

server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        root /var/www/html;
        index index.html;
    }
}

Leave a Reply

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