Nginx is a popular open-source web server that is widely used for serving static content, as well as acting as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols. It is known for its high performance, stability, and scalability, making it an excellent choice for hosting websites and applications.
In this article, we will walk you through the step-by-step process of installing Nginx on CentOS 8. CentOS 8 is a widely used Linux distribution known for its stability, security, and long-term support.
Before we begin, make sure you have root or sudo privileges on your CentOS 8 server, as we will be using some commands that require elevated permissions.
Step 1: Update System Packages
Before installing any software, it is always a good practice to update the system packages to the latest versions. Open the terminal and run the following command:
```shell sudo dnf update ```
This command will update all the packages installed on your CentOS 8 server.
Step 2: Install Nginx
Now that your system packages are up to date, you can proceed to install Nginx. Run the following command to install the Nginx package:
```shell sudo dnf install nginx ```
This command will download and install Nginx and all its dependencies on your CentOS 8 server. You will be prompted to confirm the installation, so type ‘y’ and press Enter to proceed.
Step 3: Start and Enable Nginx
Once the installation is complete, you can start the Nginx service and enable it to start automatically on system boot. Run the following commands:
```shell sudo systemctl start nginx sudo systemctl enable nginx ```
The first command starts the Nginx service, and the second command enables it to start on system boot.
Step 4: Firewall Configuration
By default, CentOS 8 comes with a firewall package called firewalld. You need to allow incoming HTTP and HTTPS traffic through the firewall to access the Nginx server.
To allow incoming HTTP traffic, run the following command:
```shell sudo firewall-cmd --zone=public --permanent --add-service=http ``` To allow incoming HTTPS traffic, run the following command: ```shell sudo firewall-cmd --zone=public --permanent --add-service=https
After running these commands, reload the firewall rules for the changes to take effect:
```shell sudo firewall-cmd --reload ```
Step 5: Verify Nginx Installation
To ensure that Nginx is installed and running correctly, open your web browser and enter your server’s IP address or domain name in the address bar. You should see a default Nginx page confirming the successful installation.
If you see the default Nginx page, congratulations! You have successfully installed Nginx on CentOS 8.
Step 6: Configure Nginx
The Nginx configuration files are located in the /etc/nginx directory. You can customize the Nginx server configuration according to your needs.
To make any changes to the default Nginx configuration, open the main configuration file using a text editor:
sudo vi /etc/nginx/nginx.conf
Make the necessary modifications, save the file, and then restart the Nginx service for the changes to take effect:
sudo systemctl restart nginx
In this article, we have learned how to install Nginx on CentOS 8. We covered the step-by-step process, from updating system packages to configuring Nginx. Now you can start using Nginx to serve your websites and applications on your CentOS 8 server. Nginx’s performance, stability, and scalability make it an excellent choice for hosting a wide range of web services.