How to Install Nginx on CentOS, Debian & Ubuntu?

Install Nginx  on CentOS, Debian & Ubuntu

In this guide, we will show you how to install Nginx on CentOS, Debian, and Ubuntu. Whether you are setting up a web server or a reverse proxy, these simple steps will help you get Nginx running smoothly on your system. The Nginx is a free, open source, lightweight and high-performance web server designed for high-traffic use cases. It is also acts as a popular Web server behind the Apache Web server and Microsoft’s IIS. Nginx is more resource-friendly than Apache. It can be served in front of other web servers as a reverse proxy.

All Nginx configuration files are stored in the /etc/nginx/ directory and /etc/nginx/nginx.conf is the the primary configuration file.

The the default server root directory in centos is /usr/share/nginx/html and in ubuntu and debian it is /var/www/html

Also any additional server block (virtual hosts in apache 2) for a website can be added in the location /etc/nginx/conf.d

Why Choose Nginx?

Nginx is a free, open-source software known for its high performance, stability, and low resource usage. It can act as both a web server and a reverse proxy, making it versatile for a variety of use cases, such as hosting websites, serving static content, and handling high-traffic loads.

  • Performance: Nginx uses an asynchronous, event-driven model to handle multiple connections simultaneously, making it more efficient than traditional web servers like Apache.
  • Low Resource Usage: Nginx can handle thousands of simultaneous connections with relatively low memory usage, making it ideal for high-traffic websites.
  • Reverse Proxy: Nginx is also widely used as a reverse proxy server to balance the load between backend servers.

Installation on Centos7

Run the following commands to install Nginx:

yum install epel-release
yum install nginx

Nginx does not start automatically even after the installation is completed. Run the following command to start the Nginx process:

systemctl start nginx

Run the following command to make sure the service is running:

systemctl start nginx
output:
nginx (pid 2735) is running…

Run the following command to restart Nginx:

systemctl restart nginx
output:
Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Installation on Centos6

Run the following commands to install Nginx:

yum install epel-release
yum install nginx

Run the following command to start the Nginx process:

service nginx start

Run the following command to make sure the service is running:

service nginx status
output:
nginx (pid 2735) is running…

Run the following command to restart Nginx:

service nginx restart
output:
Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Installation on Ubuntu, Debian

Run the following command to install Nginx:

apt update
apt install nginx

Run the following command to start apache:

/etc/init.d/nginx start

Run the following command to make sure the service is running:

/etc/init.d/nginx status
Output:
nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-09-26 16:08:19 UTC; 1 day ago
Docs: man:nginx(8)
Main PID: 2369 (nginx)
Tasks: 2 (limit: 1153)
CGroup: /system.slice/nginx.service
├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2380 nginx: worker proces

Run the following command to restart apache:

/etc/init.d/nginx restart
output:
[ ok ] Restarting nginx (via systemctl): nginx.service.

After installation is completed, you can check whether the Nginx is installed or not by entering server IP address into your browser’s address bar:

http://your_server_ip

You can see the default Nginx web page as shown below if it is successfully installed.

Nginx web server
GET STARTED WITH OUR HOSTING SUPPORT SERVICES

By following these steps, you can easily install Nginx on CentOS, Debian, and Ubuntu systems. Nginx provides a robust, scalable, and lightweight solution for serving websites and acting as a reverse proxy. With proper configuration, Nginx can handle high-traffic websites efficiently and securely.

Rohith Krishnan

Rohith SK is an MSC computer science graduate living in Cochin, Kerala. As a technology enthusiast, he is always on the lookout for the latest trends and developments in the field, with a particular interest in cloud computing and DevOps updates. Apart from his passion for technology, Rohith SK is an avid reader and enjoys spending his free time exploring different genres of literature. He believes that reading is one of the best ways to expand one's knowledge and understanding of the world. With his expertise in computer science and a passion for technology, Rohith SK regularly contributes articles and blog posts on the latest trends and updates in the industry. His articles offer insights and valuable perspectives on the various aspects of cloud computing and DevOps, and are widely read and appreciated by readers all over the world. As an experienced technology writer and researcher, Rohith SK's articles are well-researched, informative, and easy to understand, making them accessible to readers of all levels of technical knowledge. Whether you're a beginner looking to learn more about the latest trends in technology, or an experienced professional seeking insights and updates, Rohith's articles are sure to provide valuable information and insights.

Leave a Reply