How To Start Nginx On Centos 7


How To Start Nginx On Centos 7

Overview

Nginx is a high-performance web server that is used to serve web pages and applications. It is a widely-used open source software project that is written in the C programming language. Nginx is usually integrated with other web technologies such as PHP, Perl, Python, and Node.js to provide a complete web solution for any type of application. In this article, we will discuss how to get started with Nginx on CentOS 7 server.

Prerequisites

Before starting with the installation of Nginx on your CentOS 7 server, make sure that you have a user account with sudo privileges. You should also have configured the system to keep it secure before taking any steps regarding software installation.

Installing Nginx on CentOS 7

Nginx can be installed in a few different ways on CentOS 7. You can install it from the official CentOS 7 yum repository, from the third-party repositories like EPEL and the Nginx official repository, or from the source code. In this article, we will discuss the installation from the CentOS 7 repository.

Step 1: Update the System

Before we start installing Nginx, we need to update the system packages to make sure we have the latest version. We can do this using the yum package manager. To do this, run the following command:


sudo yum update

This command will update the system packages and we can continue with the installation.

Step 2: Install Nginx

Once the system packages are updated, we can install the Nginx packages by using the following command:


sudo yum install nginx

This command will install the Nginx packages and all the related packages and dependencies.

Step 3: Start and Enable Nginx

Once the installation is complete, we need to start and enable the Nginx service. To do this, we can use the following commands:


sudo systemctl start nginx
sudo systemctl enable nginx

The first command will start the Nginx service and the second command will enable it, so it will start automatically when the server restarts.

Step 4: Check the Status of Nginx

You can use the following command to check the status of the Nginx service:


sudo systemctl status nginx

The output should be similar to the following:


[root@host ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-05-11 03:36:53 EDT; 3s ago
Docs: man:nginx(8)
Main PID: 25753 (nginx)
CGroup: /system.slice/nginx.service
├─25753 nginx: master process /usr/sbin/nginx
└─25764 nginx: worker process

Testing the Installation

To test if Nginx is installed correctly we need to access the server with a web browser. If we are working on the server where Nginx is installed, then we can open the localhost address (127.0.0.1). If you are accessing it from a remote machine, then we can use the IPv4 address of the server, for example http://203.0.113.2.

When you open the url in a web browser, you should see the default Nginx page. This clearly indicates that Nginx is installed and running correctly on your system.

FAQs

Q1. How do I start Nginx in CentOS 7?

First, you need to install Nginx using yum install nginx. Then, you can start and enable the Nginx service using the following commands: sudo systemctl start nginx and sudo systemctl enable nginx.

Q2. How do I check the status of Nginx in CentOS 7?

You can check the status of the Nginx service by running the command sudo systemctl status nginx. The output should be similar to the following:>


[root@host ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-05-11 03:36:53 EDT; 3s ago
Docs: man:nginx(8)
Main PID: 25753 (nginx)
CGroup: /system.slice/nginx.service
├─25753 nginx: master process /usr/sbin/nginx
└─25764 nginx: worker process

Q3. How do I access the Nginx website from a remote machine?

You can access the Nginx website from a remote machine using the IPv4 address of the server, for example http://203.0.113.2.

Conclusion

In this article, we discussed how to get started with Nginx on CentOS 7 server. We discussed how to install, start and enable Nginx on the server and also how to test the installation. We hope that you were able to follow along and were able to successfully install and configure Nginx on your server.

Thank you for reading this article. Please read other articles on our blog for more interesting topics.

Leave a Reply

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