Before we dive into the tutorial on installing Nginx on Ubuntu 23.10, let us briefly introduce Ubuntu 23.10. Ubuntu is a popular Linux distribution based on Debian, known for its ease of use and strong community support. Ubuntu 23.10, codenamed “Lunar,” continues this tradition with updated software packages, improved system stability, and enhanced performance. Whether for a personal project, a server environment, or cloud computing, Ubuntu 23.10 is a versatile OS that caters to a wide range of users.
Now, let’s move on to installing Nginx on Ubuntu 23.10. Nginx is a powerful, open-source web server that is known for its high performance, stability, and rich feature set. It is used by many websites across the globe and is a great choice for hosting web applications.
Here’s a step-by-step guide to installing Nginx and configuring it on Ubuntu 23.10:
Step 1 – Updating Package Information
Before installing any new software, it’s always a good practice to update the package information on your system. This ensures you get the latest versions of packages from the repositories.
sudo apt-get update
Step 2 – Installing Nginx
You have two options for installing Nginx: using the default Ubuntu repository or the official Nginx repository. For the most up-to-date version, we will use the official Nginx repository.
Installing from the Official Nginx Repository
- Install the prerequisites:
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
- Import the official Nginx signing key:
curl -s https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
- Add the repository to your system:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
- Set up repository pinning:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
- Install the Nginx package:
sudo apt update
sudo apt install nginx
- Start Nginx:
sudo nginx
- Verify the installation:
curl -I 127.0.0.1
You should see output similar to:
HTTP/1.1 200 OK
Server: nginx/1.25.1
Step 3 – Adjusting the Firewall
If you have ufw
firewall enabled, you need to allow HTTP and HTTPS traffic.
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
Step 4 – Managing the Nginx Process
To ensure that Nginx starts automatically when your server boots:
sudo systemctl enable nginx
To start, stop, or restart Nginx:
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
Step 5 – Setting Up Server Blocks
To host a website, you’ll need to set up a server block (similar to virtual hosts in Apache):
- Create a directory for your website:
sudo mkdir -p /var/www/your_domain/html
- Assign ownership of the directory:
sudo chown -R $USER:$USER /var/www/your_domain/html
- Create and edit a new configuration file in Nginx’s
sites-available
directory:
sudo nano /etc/nginx/sites-available/your_domain
- Add the following content, adjusting for your domain and document root:
server {
listen 80;
server_name your_domain www.your_domain;
location / {
root /var/www/your_domain/html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
}
- Enable the file by creating a link to the
sites-enabled
directory:
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
- Test your Nginx configuration for syntax errors:
sudo nginx -t
- If no errors are reported, restart Nginx:
sudo systemctl restart nginx
Conclusion
Congratulations! You have successfully installed and configured Nginx on your Ubuntu 23.10 server. This sets a solid foundation for hosting your web applications.
Shape.host Services
For a robust and reliable hosting solution, consider using Shape.host’s Linux SSD VPS services. Their high-performance SSD-based virtual servers are optimized for speed and reliability, providing an excellent hosting environment for your Nginx server. Check out Shape.host for Linux SSD VPS packages that suit your needs, whether you’re hosting a small personal site or a large-scale commercial application.