Installing NGINX on CentOS

31 Dec 2019 10 min See Original (spanish)

What is NGINX

NGINX is an open source application that allows us to create web servers, reverse proxies, caches, load balancers, and more. It was created to deliver maximum performance and stability, as well as functionalities for being used as a proxy for a mail server.

Because running ASP.NET applications requires a reverse proxy, I have chosen NGINX over Apache, as I found it much easier to configure. 

For now, in this post, we will treat it as a web server.

Remember, you should be logged into the server, either physically or through SSH, to perform these steps. 

 

 

1 - Install NGINX

The first step is to install NGINX on our CentOS server. To do this, make sure you have the EPEL repository installed with the following command

$ sudo yum install epel-release

Next, proceed to install NGINX 

$ sudo yum install nginx

Just indicate that you should answer yes (y) when asked to install the server. 

 

 

2 - Start NGINX

This means we have our server installed, so the only thing left is to start the service by running the following command

$ sudo systemctl start nginx

And don’t forget to enable it at startup, in case the server is ever restarted. To do that, run the command

$ sudo systemctl enable nginx

As you can see, it's very similar to the steps for FTP and SQL we’ve seen before. And as with FTP, if you want to access it externally (not needed with SQL, at least for now), you’ll need to open two more firewall ports. This time, the corresponding HTTP and HTTPS ports.

Note: later on, we’ll see how to install a valid certificate for your site to use SSL

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

With that, you’ll have access to ports 80 and 443

 

 

3 - Check NGINX server

To check that our web server is working correctly, simply go to your browser and enter 

http://server_ip

Where server_ip is the IP of your server (the same one you use for ssh).

If you have a domain name, you can enter the domain, although sometimes DNS servers can take a while to update (up to 24h), so using the IP is more reliable in this case. 

When you hit enter, you’ll see a plain HTML page that says "Welcome to nginx", this is the default page for the nginx server. 

 

4 - NGINX Configuration

We’re not going to alter the configuration files for now, but a brief introduction about them is always useful.

The first one is the web server directory, located at /usr/share/nginx/html, but we’ll change this later when we look at the reverse proxy.

The main configuration file is found at /etc/nginx/nginx.conf, but the default configuration is located at /etc/nginx/conf.d/default.conf

You can extend or modify this configuration by adding files to the /etc/nginx/conf.d folder. Any file you place in this folder with the .conf extension will be loaded when NGINX starts.

 

Conclusion

In this post, we've covered how to install NGINX as a web server and where to find the configuration files. 

 

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café