How to install nginx on Centos 7 Print

  • 1

Nginx is one of the most popular web servers in the world and is used by many large Internet portals. It can be used not only as a web server, but also as a reverse proxy. Nginx has many advantages, for example, it consumes fewer resources compared to Apache.


Step one. Adding an Nginx repository
To add CentOS 7 EPEL, open a terminal and enter the following command:


yum install epel-release

Step two. Installing Nginx
Now that the Nginx repository has been added on your server, install Nginx using the following yum command:

 

yum install nginx
Once you answer yes to the prompt, Nginx will complete installation on your virtual private server (VPS).

 

Step three. Starting Nginx
Nginx does not start on its own. To start Nginx, type the following:

 

sudo systemctl start nginx

If you are using a firewall, run the following commands to allow HTTP and HTTPS traffic:

 

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

You can do a spot check right away to make sure everything went as planned by visiting your server's public IP address in your web browser

 

http://server_domain_name_or_IP/


You will see the default Nginx web page in CentOS 7, which is for informational and testing purposes

 


Before you continue, you'll probably want to enable Nginx to start at system boot. To do this, enter the following command:

 

sudo systemctl enable nginx

 

Root Server and Configuration
If you want to start serving your own pages or applications through Nginx, you will want to know the location of the configuration files and the default server root directory of Nginx.

Default root server
The default server root directory is /usr/share/nginx/html. Files placed there will be served on your web server. This location is specified in the server-side default block configuration file that ships with Nginx, which is located in the file /etc/nginx/conf.d/default.conf.

Server block configuration
Any additional server blocks, known as virtual hosts in Apache, can be added by creating new configuration files in the /etc/nginx/conf.d file. Files that end with .conf in this directory will be loaded during Nginx startup.

Global Nginx configurations
The main Nginx configuration file is located in the /etc/nginx/nginx.conf file. Here you can change settings like the user who starts the Nginx daemon process, the number of worker processes that are spawned when Nginx is running.


Was this answer helpful?

« Back