Upgrading Nginx from version 1.18 to 1.25 (Ubuntu 20.04)
Introduction
This article delves into the step-by-step process of upgrading Nginx from version 1.18 to 1.25 on an Ubuntu 20.04 server, highlighting the intricacies and considerations involved in such a task.
The Challenge
Nginx, a popular web server known for its performance and flexibility, often releases updates that introduce new features, security patches, and performance improvements. For a system administrator, keeping Nginx up-to-date is essential. However, this task can be challenging, especially when the required version is not available in the standard Ubuntu repositories. This was the case with Nginx 1.25, which at the time of the upgrade was only available in the mainline repository.
Upgrading Nginx from version 1.18 to 1.25 on an Ubuntu 20.04 server involves several steps. You need to add the Nginx mainline repository to your system, update the package list, and then perform the upgrade. Here’s a step-by-step guide:
Step 1: Backup Configuration Files: Before making any changes, it’s always a good practice to backup existing configuration files. You can do this by copying the /etc/nginx
directory.
sudo cp -r /etc/nginx /etc/nginx-backup
Step 2: Add Nginx Mainline Repository: Since Nginx 1.25 is available in the mainline repository, you need to add this repository to your system.
First, import the repository’s key
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
Then, add the repository:
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Step 3: Update Package Lists: Update the local package lists to include the new additions from the Nginx mainline repository
sudo apt-get update
Step 4: Install the New Version of Nginx: Now, upgrade Nginx to the new version.
sudo apt-get install nginx
This command will install the latest version of Nginx available in the mainline repository you’ve added, which should be 1.25.* as of your current information.
Step 5: Verify the Upgrade: After the installation process completes, you can verify the upgrade by checking the version of Nginx
nginx -v
This should show version 1.25.*
Step 6: Review and Merge Configuration: If you had custom configurations in your previous Nginx setup, you might need to merge those changes with the new configuration files. Compare your backup with the current configuration and make necessary adjustments.
Step 7: Restart Nginx: Finally, restart Nginx to apply any configuration changes.
sudo systemctl restart nginx
Step 8: Test Your Configuration: Ensure that your websites or applications are functioning as expected. It’s a good idea to check the error logs for any issues.
sudo nginx -t sudo systemctl status nginx
Check the error logs if you encounter any issues:
less /var/log/nginx/error.log
Secure Your Installation: If you haven’t already, consider securing your Nginx installation with additional measures such as setting up a firewall, implementing SSL/TLS, and regular security audits.
Conclusion
Remember, it’s crucial to stay updated with any future changes or updates from Nginx, especially concerning security updates. Keep an eye on the Nginx announcements or subscribe to their mailing list for updates.