How to install and configure an Nginx server on CentOS?
The steps for installing and configuring Nginx server in CentOS are as follows:
- Update the system: First, make sure the system is updated to the latest version by using the following command.
sudo yum update
- Install Nginx: Use the following command to install Nginx:
sudo yum install nginx
- To start the Nginx service: After installation, use the following command to start the Nginx service:
sudo systemctl start nginx
- To enable Nginx to start automatically upon booting, use the following command:
sudo systemctl enable nginx
- Set up the firewall: If the firewall is enabled, open port 80 to allow HTTP traffic to pass through.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
- Setting up Nginx: The Nginx configuration file is located at /etc/nginx/nginx.conf and can be modified as needed. Common configurations include changing the listening port and setting up virtual hosts.
- Test Nginx: Open a browser and visit the server’s IP address or domain name. If you see the Nginx welcome page, it means that Nginx has been successfully installed and configured.
You can install and configure an Nginx server in CentOS by following the steps above.