Nginx is an open-source high-performance web server created by Igor Sysoev. It is also used for reverse proxy, mail proxy, load balancing, caching, and media streaming.
Nginx is one of the most used web server because of its high performance, speed, and low memory consumption. It can handle around 10000 simultaneous connections with a very low memory input.
Steps to install Nginx :
- Install EPEL repository on your server.
sudo yum install -y epel-release
- Use yum command to install Nginx.
sudo yum install nginx
- Start Nginx with systemctl command.
sudo systemctl start nginx
- To check Nginx’s status, use systemctl status.
sudo systemctl status nginx

- Configure the firewall to allow HTTP and HTTPS traffic.
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
- Go to your browser and verify if Nginx is running by visiting your server’s public IP. You would see the default Nginx webpage.
http://server-public-IP/

The following are the steps to deploy a web application on Nginx:
- Navigate to the configuration file for Nginx.
sudo vi /etc/nginx/nginx.conf
- Look for server block in file.

- In the root directive, specify the location of your HTML file. The default location is where Nginx webpage html file is present. The default listening port is 80 which can be changed according to the use case.

- We have changed the root location to /var/www/html. Now restart Nginx.
sudo systemctl reload nginx sudo systemctl restart nginx
- Now visit your server’s public IP from the browser. You will see your application.

Steps to enable password protection in Nginx:
- Create a .htpasswd file with the command below.
sudo htpasswd -c /etc/nginx/.htpasswd 'username'
- Enter password when prompted.
- Open configuration file.
sudo vi /etc/nginx/nginx.conf
- Add following code in location directive in server block.
auth_basic "Restricted Content"; auth_basic_user_file /etc/nginx/.htpasswd;

- Restart Nginx.
sudo systemctl reload nginx sudo systemctl restart nginx
- Go to your browser and visit your application, you will see a prompt asking for a username and password.

Call us to have a conversation with our technical consultant to talk about your infrastructure management optimization or offshore cloud infrastructure support team.
