Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Install and Configure Nginx from Source on Linux
Next article icon

How to Install and Configure Nginx from Source on Linux

Last Updated : 21 Jul, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Nginx is written in C language by Igor Sysoev to overcome the C10K problem (i.e. Concurrently handling 10k(ten thousand) connections). The problem was how to optimize the network socket to handle numerous clients at the same time. Nginx is a solution to that problem. It is a free and open-source software for reverse proxying, load balancer, web serving, media streaming, etc. It is pronounced as "Engine X", by eliminating the letter "e" from this, the name becomes "Nginx". In this article, we are going to see a step-by-step guide on how to install and configure the Nginx server from the source.

Features of Nginx:

  1. It supports reverse proxy with caching.
  2. It supports WebSockets, load balancing, and fault tolerance.
  3. It supports FastCGI  with caching.
  4. It can be used for handling static files, index files, and auto-indexing.
  5. It supports SSL.
  6. Both name-based and IP-based virtual servers can be configured in Nginx.
  7. HTTP basic authentication
  8. All the main mail proxy server features are supported in Nginx.

Installation of Nginx

Step 1: Download the Nginx archive from this link and save the archive file on your desktop.

Nginx Download page

Or, you can download the Nginx web server archive file by running the following command in the terminal.

wget http://nginx.org/download/nginx-1.21.1.tar.gz
Downloading the Nginx server

wget will fetch the archive file and save it to the location where you have opened the terminal.

Step 2: After downloading the archive, we need to navigate the folder where we have downloaded that archive and have to extract the archive using any archive utility. You can run the following command to extract the Nginx archive file.

tar -xf nginx-1.21.1.tar.gz

After this, the folder structure should look like this.

Nginx folder

Step 3: Now, to begin the installation of Nginx, navigate to the extracted folder and open the terminal here, then run the following command.

  • Navigate to the directory by running the following command:
cd ~/Desktop/nginx-1.21.1
  • Start the configuration installer of the Nginx.
./configure

Here below is a summary of the configuration file:

Configuration summary    + using system PCRE library    + OpenSSL library is not used    + md5: using system crypto library    + sha1: using system crypto library    + using system zlib library      nginx path prefix: "/usr/local/nginx"    nginx binary file: "/usr/local/nginx/sbin/nginx"    nginx configuration prefix: "/usr/local/nginx/conf"    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"    nginx pid file: "/usr/local/nginx/logs/nginx.pid"    nginx error log file: "/usr/local/nginx/logs/error.log"    nginx http access log file: "/usr/local/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"
  • Build the Nginx package from the source using the make command.
make
  • Run the make install command to install the built package.
sudo make install

This command will install Nginx in the /usr/local/nginx directory.

Step 4: Confirm the installation and check the installed version of Nginx by running the following command:

Navigate to /usr/local/nginx using the cd command (change directory):

cd /usr/local/nginx/sbin

To check what is the current installed version of the Nginx.

./nginx -v
Successfully installed Nginx

Starting the Ngnix server 

Follow the following steps to start an Nginx server.

  1. Navigate to the default location where Nginx is installed by running the following command in the terminal.
cd /usr/local/nginx/sbin

         2. Now, we can start the Nginx server by running the following command:

sudo ./nginx

To see if it's working, go to the local host or your URL.

Nginx start (Welcome page)

Change the default Nginx listen port

By default, the Nginx is configured to listen on port 80. If you want to change the default Nginx listening port, you can do that by reconfiguring the nginx.conf file located under /usr/local/nginx/conf.

Steps to change the default Nginx Listen Port.

Step 1: Open the nginx.conf file by running the following command:

sudo nano /usr/local/nginx/conf

Step 2: After opening, the nginx.conf file should look like this:

configuring listen port

Navigate to this server section and change listen 80; port to any other port number, e.g. 5555, etc.

Step 3: Save the file and run open the localhost with port 5555 as follows.

custom listen port

Stopping the Nginx server

To stop the Nginx server, we just need to add the flag -s  to stop the Nginx command as follows.

sudo ./nginx -s stop

This will stop the Nginx server, you can refresh the localhost page and see.

Nginx stop

Uninstalling the Nginx server

To uninstall Nginx, run the following command in the terminal with superuser permissions, i.e. sudo :

sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx

This will completely remove Nginx from your machine. Here, we are using rm command to remove the directories and subdirectories using -f and -R flags. -f is used to remove the directories, and -R will recursively remove all the directories within directories. Using &&, we can write multiple commands in a single line.


Next Article
How to Install and Configure Nginx from Source on Linux

R

rriicchhaa
Improve
Article Tags :
  • Linux-Unix
  • Linux-Tools

Similar Reads

    How To Install Nginx On Amazon linux ?
    Nginx, at first conveyed in 2004 by Igor Sysoev, is a decent open-source web server, switch go-between, load balancer, and HTTP store. With its occasion-driven planning, Nginx productively handles endless simultaneous affiliations, making it ideal for high-traffic districts and applications.It keeps
    6 min read
    How to install and configure Nginx Web Server on Godaddy VPS (Ubuntu)?
    GoDaddy Server is a cloud-based hosting platform that consists of virtual and dedicated servers. The premium service includes weekly backups, 99% uptime, 24x7 Customer Support, a free encrypted SSL certificate, unlimited bandwidth, and SSD storage. For regular users, the latest generation is VPS Gen
    2 min read
    How to install and configure Docker on Godaddy server?
    In this article, we will discuss how to install the latest version of Docker on GoDaddy VPS (Ubuntu). Installing Docker on Godaddy Server Step 1: Open your terminal and ssh into the GoDaddy Server. $ ssh [username]@[ip] Step 2: Update and upgrade the server by running. $ sudo apt update -y $ sudo ap
    1 min read
    How to Install and use PHP Composer on Linux?
    A composer is a tool that is used for dependency management in PHP. But Composer is not a package manager. Composer is an application-level manager that is completely used for PHP programming language. A package manager is used to import codebases into the project and make it up to date. Composer he
    3 min read
    How to Install and Configure Apache on openSUSE or SLES?
    The most popular web server is Apache, also known as the Apache HTTP server. This post will walk you through installing and configuring Apache on SLES or openSUSE.PrerequisitesA running instance of openSUSE or SLES.A user with sudo privileges.Steps to install and configure Apache on openSUSE or SLES
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences