How to Install Nginx on CentOS, Debian & Ubuntu?

Install Nginx  on CentOS, Debian & Ubuntu

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

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

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