To install and configure Nginx on Ubuntu 24.04, follow these steps:
Step 1 : Ensure your system is up to date by running:
sudo apt update
Step 2 : Install Nginx using the following command:
sudo apt install nginx
Step 3 : Check available application profiles for ufw:
sudo ufw app list
Allow Nginx Full profile:
sudo ufw allow 'Nginx Full'
Step 4 : Check the status of Nginx to ensure it's running:
sudo systemctl status nginx
Step 5 : Create a directory for your website, for example, example.com, and add an index file:
sudo mkdir -p /var/www/example.com/html
sudo nano /var/www/example.com/html/index.html
- Add some content to the index.html file. For example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to example.com</title>
</head>
<body>
<h1>Welcome to example.com</h1>
<p>This is the default landing page for your domain.</p>
</body>
</html>
Step 6 : Create a new server block configuration file for your domain:
sudo nano /etc/nginx/sites-available/example.com
Add configuration details for your domain. Here's a basic example:
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
Step 7 : Link the configuration file from sites-available to sites-enabled to enable the site:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Step 8 : Restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 9 : Visit your domain (example.com) in a web browser to ensure Nginx is serving your website correctly.
Congratulations! You have successfully installed and configured Nginx on Ubuntu 24.04.
Recommended
![How to Install Ubuntu Server 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f2cec9d5274.small.jpg)
![How to Update Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f31ce6731ae.small.jpg)
![How to Enable SSH on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f31d5688179.small.jpg)
![How to Enable Root Login Via SSH on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f320d568b02.small.jpg)
![How to Enable SSH Password Login on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f32212a3bc2.small.jpg)
![How to Set or Change Hostname on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f326eec5f87.small.jpg)
![How to Create a Swap File on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-14/65f3446100147.small.jpg)
![How to Configure SSL for Apache on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-15/65f3f4f551f02.small.jpg)
![How to Install MariaDB on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-15/65f3fe7135af6.small.jpg)
![How to Install Nginx on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-15/65f43dd2ca46b.small.jpg)
![How to Configure SSL for Nginx on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-15/65f4593fd29ba.small.jpg)
![How to Install PHP 8.3 for Nginx on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-16/65f512ad4086e.small.jpg)
![How to Install Node.js on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f6511a5e1f4.small.jpg)
![How To Install NVM on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f6991d4ddf3.small.jpg)
![How to Install Yarn on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f656027d55f.small.jpg)
![How to Install PM2 in Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f69c3ad6554.small.jpg)
![How to Setup SFTP Server on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f659ae697c2.small.jpg)
![How to Install vsftpd FTP Server on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f6b59eba85f.small.jpg)
![How to Install PHP 7.2 on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-05-02/663324c9362c3.small.jpg)
![How to Install PHP 7.4 on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-05-02/66332705418bc.small.jpg)
![How to Install PHP 8.0 on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-05-02/66333783e162e.small.jpg)
![How to Install PHP 8.2 on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-05-02/663338cb7a340.small.jpg)
![How to Install PHP 8.3 on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-05-02/66333ab801108.small.jpg)
![How To Install Docker on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f68e73bf9e7.small.jpg)
![How to Install and Use Podman on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-17/65f6902ed188c.small.jpg)
![How to Install and Use rsync on ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-19/65f98c8c0ff4e.small.jpg)
![How to Install Git on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-19/65f98fd1767f9.small.jpg)
![How to Install Neofetch on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-20/65faeae13e914.small.jpg)
![How To Install Elasticsearch on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-19/65f996a915c72.small.jpg)
![How to Install Usermin on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-19/65f9ba0206f3a.small.jpg)
![How to Install Webmin on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-20/65faa57ac6801.small.jpg)
![How To Install Memcached on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-20/65fa789b4789a.small.jpg)
![How to Install RabbitMQ on Ubuntu 24.04](https://api.devtutorial.io/uploads/2024-03-20/65fa60115de41.small.jpg)