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
- Then, install the Nginx web server with:
sudo apt install nginx -y
- Now, check the installed Nginx version:
sudo nginx -version
- The output should look similar to this:
nginx version: nginx/1.24.0 (Ubuntu)
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
- Then, manually start the Nginx service:
sudo systemctl start nginx
- To stop the Nginx service:
sudo systemctl stop nginx
- Then, apply configuration changes by restarting Nginx:
sudo systemctl restart nginx
- Next, confirm Nginx is running:
sudo systemctl status nginx
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
- 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;
}
}
- Then, save and close the file.
- Now, it is time to validate the Nginx configuration:
sudo nginx -t
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
- 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/
- Next, create the directory to store the web application files:
sudo mkdir -p /var/www/app.example.com
- Now, create an `index.html` file for testing:
sudo nano /var/www/app.example.com/index.html
Add this sample HTML:
<html>
<head></head>
<body>
<h1>Greetings from Vultr</h1>
</body>
</html>
- Then, save and close the file.
- Now, apply the new virtual host configuration:
sudo systemctl restart nginx
- Confirm Nginx serves the virtual host:
curl http://app.example.com
The output should display:Greetings from Vultr
Step 4: Configure Firewall Rules
- Enable HTTP (port 80):
sudo ufw allow 80/tcp
- Enable HTTPS (port 443):
sudo ufw allow 443/tcp
- Check active firewall rules:
sudo ufw status
[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