Exercises to perform:
- Install Nginx.
- Enable and start Nginx.
- Add a port to firewalld.
- Create a simple website.
- Check if the page displays correctly using the IP address.
Install Nginx
SLES
To install Nginx, type:
# refresh repositories
sudo zypper ref
# install Nginx
sudo zypper -n in nginx
# enable Nginx at system startup
sudo systemctl enable nginx
# start Nginx
sudo systemctl start nginx
Debian
To install Nginx, type:
# refresh repositories
sudo apt update
# install Nginx
sudo apt -y install nginx
# enable Nginx at system startup
sudo systemctl enable nginx
# start Nginx
sudo systemctl start nginx
Red Hat
To install Nginx, type:
# install Nginx
sudo yum install nginx -y
or
sudo dnf install nginx -y
# enable Nginx at system startup
sudo systemctl enable nginx
# start Nginx
sudo systemctl start nginx
Allow Nginx service
SLES
linux:~ # sudo firewall-cmd --add-service=http --permanent
linux:~ # sudo firewall-cmd --add-service=https --permanent
success
linux:~ # sudo firewall-cmd --reload
success
Debian
sudo ufw allow 'WWW'
or
sudo ufw allow 'Nginx'
Red Hat
linux:~ # sudo firewall-cmd --add-service=http --permanent
linux:~ # sudo firewall-cmd --add-service=https --permanent
success
linux:~ # sudo firewall-cmd --reload
success
Create a simple website
echo 'Linux Basics - laboratory' | sudo tee -a /srv/www/htdocs/index.html
Check if the site displays correctly using the IP address
curl http://checkip.amazonaws.com
curl http://IP-ADDRESS
Additional modules
After starting the Nginx server, you can enable additional modules to obtain extended functionality.
To check the list of additional modules, write the command:
sudo zypper search nginx
Assuming you want to install the ModSecurity module. You can do this by running the following command:
SLES
sudo zypper -n in nginx-module-modsecurity
Debian
sudo apt install nginx-plus-module-modsecurity
Red Hat
sudo yum install nginx-plus-module-modsecurity
or
sudo dnf install nginx-plus-module-modsecurity
Add the following line to the main section in the /etc/nginx/nginx.conf file
load_module modules/ngx_http_modsecurity_module.so;
Restart Nginx.
SLES
sudo systemctl restart nginx
Debian
sudo systemctl restart nginx
Red Hat
sudo systemctl restart nginx
Run the following command to check if the module has loaded successfully:
sudo nginx -t
The result should be as below:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
More about WAF configuration here: Configuring the NGINX ModSecurity WAF with a Simple Rule