frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[CentOS] How to install Nginx

LawrenceLawrence Member
edited September 25 in Linux Applications

Nginx (pronounced "engine x") is a web server. It can act as a reverse proxy server for TCP, UDP, HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache. It's one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet.

In this tutorial we are using CentOS 7, however you should be able to install it on all our offered CentOS version.



WARNING

CentOS 7 reached the EOL June 30, 2024:

https://blog.centos.org/2023/04/end-dates-are-coming-for-centos-stream-8-and-centos-linux-7/

Because of this, you may encounter some repository issues. We recommend that you reinstall another OS that has not yet reached EOL.

If you are using CentOS 7 and encounter a mirror issue, please check out this guide to resolve the problem.

Nginx vs. Apache

Both web servers, in their latest versions, can compete with each other in most areas. For static content NGINX is king, but for dynamic content the performance difference is quite slim. NGINX does shine with some of its more advanced features (media streaming, reverse proxying for non-HTTP protocols), as well as its commercial support and training.

High-traffic website owners that need to serve a lot of static content and/or media streams will probably prefer NGINX (or use a combination of Apache and NGINX). In most other website use cases, either web server will do the job just fine.

Both Apache and Nginx are powerful, flexible, and capable. Deciding which server is best for you is largely a function of evaluating your specific requirements and testing with the patterns that you expect to see.

Turning Off Apache

Every major Linux distribution comes packages with Apache by default, no exception and our offered templates. So in order to install and start using Nginx first of all we need to turn of Apache:

service httpd stop

Now we need to remove Apache from the boot cycle, so that it doesn’t try to start up during server boot:

systemctl disable httpd


Installing Nginx

Now we need to add the CentOS EPEL package so that we can install NGINX:

yum install epel-release -y

Now we can install Nginx easily:

yum install nginx -y

As IPv6 is not supported on Time4VPS servers we need to delete line about it's interface from the configuration file. We can do it with command:

sed -i '/\[::\]:80/d' /etc/nginx/nginx.conf

Start Nginx and configure server to start it upon reboot:
service nginx start
systemctl enable nginx


Checking the Web Server

After Nginx is installed we should check is it running properly. We can do it by visiting your server's hostname or IP address:

http://hostname_or_IP_of_your_server

You should see the default Nginx landing page, which should look something like this:




Server Root and Configuration

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.


Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /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 /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.


Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

Tagged:
Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch