Install Nginx With Waf Centos 7


Install Nginx With Waf Centos 7

Overview

Nginx is a popular open-source web server used for hosting websites and applications. It is widely used due to its high performance, efficient resource utilization, and simple configuration. One of the key features of Nginx is the Web Application Firewall (WAF) module which allows it to filter malicious requests and protect your websites from attackers. In this article, we will discuss how to install Nginx with WAF on CentOS 7.

Prerequisites

Before we begin with the installation, there are a few prerequisites that we need to take care of. First, make sure that you have root access to the server or a user with sudo privileges. Additionally, you should make sure that the server is equipped with the latest version of CentOS and that the operating system and software packages are up to date.

It is also important to ensure that the necessary dependencies for Nginx and WAF are installed on the server. These packages include the EPEL repository, the Nginx repository, and Nginx packages.

Add EPEL and Nginx Repository

Now, we can begin the installation process itself. First, we need to add the EPEL and Nginx repository by running the following commands on the terminal.


# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Install Nginx and WAF Packages

After the repositories have been added, we are now ready to install the necessary packages. For this, we will use the yum command to install the Nginx and WAF packages.


# yum install nginx
# yum install nginx-mod-http-waf

Enable and Start Nginx Service

Once the installation is finished, we need to enable and start the Nginx service. To do this, we can use the systemctl command as follows.


# systemctl enable nginx
# systemctl start nginx

Once the service is enabled and started, we can verify that it is running by using the systemctl command as follows.


# systemctl status nginx

Configure Nginx With WAF

Now, we need to configure the Nginx server with the WAF module. For this, we first need to create a configuration file in the /etc/nginx/conf.d/ folder.


# vim /etc/nginx/conf.d/modsecurity.conf

In the configuration file, add the following directives and save the file.


load_module modules/ngx_http_modsecurity_module.so;
modsecurity on;
modsecurity_rules_file /etc/nginx/waf/modsecurity.conf;
modsecurity_rules_file /etc/nginx/waf/crs-setup.conf;

Once the configuration is saved, verify the syntax by running the following command.


# nginx -t

Restart Nginx Service

Finally, we need to restart the Nginx service in order for the changes to take effect.


# systemctl restart nginx

Conclusion

In this article, we discussed how to install Nginx with WAF on CentOS 7. We looked at the prerequisites and then proceeded to add the EPEL and Nginx repository. We then installed the necessary packages followed by enabling and starting the Nginx service. Afterwards, we configured the Nginx server with the WAF module and verified the syntax. Finally, we restarted the Nginx service in order for the changes to take effect.

FAQs

Q: How do I check if Nginx is running?

A: You can check if Nginx is running by using the systemctl command as follows: # systemctl status nginx.

Q: How do I verify the syntax of the Nginx configuration file?

A: You can verify the syntax by running the following command: # nginx -t.

Q: How do I restart the Nginx service?

A: You can restart the Nginx service by running the following command: # systemctl restart nginx.

Thank you for reading this article. Please read our other articles for more information.

Leave a Reply

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