Learn how to install the Nginx Web Server on Ubuntu 24.04. Our Nginx Support team is here to help you with your questions and concerns.
How to Install Nginx Web Server on Ubuntu 24.04
Nginx is a powerful and efficient web server widely used to serve web applications, act as a reverse proxy, and handle load balancing.
Today, we will install Nginx on Ubuntu 24.04, configure virtual hosts, and set up firewall rules.
Step 1: Install Nginx
- First, run the following command to make sure the server’s package index is up to date:
sudo apt update
Copy Code - Then, install the Nginx web server with:
sudo apt install nginx -y
Copy Code - Now, check the installed Nginx version:
sudo nginx -version
Copy Code - The output should look similar to this:
nginx version: nginx/1.24.0 (Ubuntu)
Copy Code
Step 2: Manage Nginx System Service
Nginx uses `systemd` for service management. Here’s how to control Nginx processes:
- Ensure Nginx starts automatically when the server reboots:
sudo systemctl enable nginx
Copy Code - Then, manually start the Nginx service:
sudo systemctl start nginx
Copy Code - To stop the Nginx service:
sudo systemctl stop nginx
Copy Code - Then, apply configuration changes by restarting Nginx:
sudo systemctl restart nginx
Copy Code - Next, confirm Nginx is running:
sudo systemctl status nginx
Copy Code
Step 3: Configure Nginx Virtual Hosts
Virtual hosts allow Nginx to serve multiple domains or applications from a single server. Let’s create a new virtual host.
- First, create a new configuration file, for example, `app.example.com.conf`:
sudo nano /etc/nginx/sites-available/app.example.com.conf
Copy Code - Then, add the following content:
server { listen 80; listen [::]:80; server_name app.example.com; root /var/www/app.example.com; index index.html; location / { try_files $uri $uri/ =404; } }
Copy Code - Then, save and close the file.
- Now, it is time to validate the Nginx configuration:
sudo nginx -t
Copy Code
Successful output will look like this:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Copy Code - Then, link the configuration file to the `sites-enabled` directory:
sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/
Copy Code - Next, create the directory to store the web application files:
sudo mkdir -p /var/www/app.example.com
Copy Code - Now, create an `index.html` file for testing:
sudo nano /var/www/app.example.com/index.html
Copy Code
Add this sample HTML:<html> <head></head> <body> <h1>Greetings from Vultr</h1> </body> </html>
Copy Code - Then, save and close the file.
- Now, apply the new virtual host configuration:
sudo systemctl restart nginx
Copy Code - Confirm Nginx serves the virtual host:
curl http://app.example.com
Copy Code
The output should display:Greetings from Vultr
Copy Code
Step 4: Configure Firewall Rules
- Enable HTTP (port 80):
sudo ufw allow 80/tcp
Copy Code - Enable HTTPS (port 443):
sudo ufw allow 443/tcp
Copy Code - Check active firewall rules:
sudo ufw status
Copy Code
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
In brief, our Support Experts demonstrated how to fix the “configmap aws-auth does not exist” error in Amazon EKS with Terraform.
0 Comments