How to install Nginx Web server on CentOS 8 Host

This tutorial focuses on how to CentOS  install Nginx Web server on the host 8.

Nginx is probably one of the most popular Web server in use today.

Nginx is pronounced "engine-x", it serves 32% of the online campaign website, higher than the Apache HTTP Web server.

Apache Nginx also serves as a load balancer or reverse proxy.

Nginx is known for its performance, even if the lack of flexibility compared with the Apache, but it can also handle a large number of incoming connections.

In this tutorial, we will see how to install Nginx on CentOS 8.

 

Install the necessary plug-ins

1
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

He said that under these role

gcc which can compile C, C ++, Ada, Object C and Java language

pcre pcre-devel pcre is a perl library, including perl-compatible regular expression library, nginx http module uses the pcre regular expressions to parse, so you need to install pcre library

zlib zlib-devel zlib library provides a variety of compression and decompression using zlib nginx way for the contents of the package are http gzip, so you need to install

openssl openssl-devel openssl security is the cornerstone of web communication, no openssl, we can say that the information is in the streaking

 

prerequisites

Before you begin, for CentOS 8 have sudo privileges are important to you.

To ensure this is the case, run the following command

$ Sudo -l

User user may run the following commands on localhost:
    (ALL) ALL

Also, make sure port 80 on the host does not have any content.

NGINX use this port by default. As a result, if you have already installed the Apache Web server, you may not be able to run NGINX server.

$ netstat -tulpn | grep :80

If this command does not show any results, then fine.

NGINX mounted on CentOS 8

In order to install NGINX on CentOS 8, you only need to install the following packages.

$ sudo yum install -y nginx

NGINX start on CentOS 8

First of all, you want to enable NGINX server to start after the host starts immediately.

[linuxidc@localhost ~]$ sudo systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

When you're ready, you can start using the following command NGINX

$ sudo systemctl start nginx

Use the status command to ensure proper started NGINX.

$ sudo systemctl status nginx

Now NGINX is running, you must acquire an IP host.

To find your current IP address on CentOS 8, run the following command

[linuxidc@localhost ~]$ sudo hostname -I | awk '{print $1}'
192.168.229.165

Congratulations!

You have successfully installed the CentOS 8 NGINX.

However, you must configure it properly, so that the public can access your website.

Check your firewall rules

To enable external users to access your Web server, you need to enable the host to the HTTP and HTTPS traffic.

Modify firewall rules and add the following entry (if not completed)

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

Manage your NGINX server on CentOS 8

In order to manage your NGINX server, you have several options.

To check the status of NGINX, you must run the following command

$ sudo systemctl status nginx

To stop your NGINX server, run

$ sudo systemctl stop nginx

If you want to restart, you must run

$ sudo systemctl start nginx

If you make some changes to the NGINX server, you can reload it without having to stop and restart it.

To reload NGINX, you simply run

$ sudo systemctl reload nginx

If you do not want to start NGINX server at boot time, you must disable it by running

$ sudo systemctl disable nginx

CentOS on best practices NGINX 8

By default, your static HTML files are located in "/ usr / share / nginx / html".

So, if you want to navigate to this path, the HTML file that is displayed when using the Web browser to find.

File Locations

If you are using NGINX as the default Web server, which means you do not request a proxy to Apache, you can use the "/ var / www" folder to different storage sites.

In addition, you must create NGINX server block, on the request to the server hosting the site to match.

However, if you request a proxy to Apache, NGINX just edit the configuration file, you can use the "/ var / www" Apache site file path.

Server block

Similarly with Apache, NGINX can handle custom configuration files to store many different sites.

These configuration files may be stored in "/etc/nginx/conf.d", and they must end .conf.

Apache and NGINX technology used is very similar, so if you are a technique used in the past, the management should on no difference.

to sum up

In this tutorial, you learned how to install NGINX on CentOS 8.

However, you should now begin creating server block to store your different sites. You can also choose to have NGINX proxy server to forward the request to the master Web server (such as Apache).

 

Guess you like

Origin www.cnblogs.com/xwhgr/p/12570274.html