
{"id":45343,"date":"2024-01-26T11:24:29","date_gmt":"2024-01-26T11:24:29","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=45343"},"modified":"2026-05-08T09:06:19","modified_gmt":"2026-05-08T09:06:19","slug":"install-nginx-ubuntu-2204","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/01\/install-nginx-ubuntu-2204\/","title":{"rendered":"Install Latest Nginx in Ubuntu 26.04, 24.04, 22.04 (Step by Step)"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-45344\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This is a step by step beginner&#8217;s guide shows how to install the latest version of Nginx web server (either mainline or stable) in Ubuntu 26.04, Ubuntu 24.04, or Ubuntu 22.04 Desktop or Server.<\/p>\n<p>Nginx is a popular free and open-source web server, that can be also used as reverse proxy, load balancer, mail proxy and HTTP cache. <\/p>\n<p>For a just working version, user can run command <code>sudo apt install nginx-full<\/code> to install it from Ubuntu system repository, which however is always old. For the latest version, you can get it from <strong>Nginx&#8217;s official repository<\/strong>.<\/p>\n<p><!--more--><\/p>\n<h3>Mainline vs Stable<\/h3>\n<p>There are 2 Nginx release series for choice. They are <strong>Mainline<\/strong> with latest features, and <strong>Stable<\/strong> which is bit old in version number.\u00a0Choose either one before getting started.<\/p>\n<blockquote><p><em>Mainline \u2013 Includes the latest features and bug fixes and is always up to date. It is reliable, but it may include some experimental modules, and it may also have some number of new bugs. Stable \u2013 Doesn&#8217;t include all of the latest features, but has critical bug fixes that are always backported to the mainline version.<\/em><\/p><\/blockquote>\n<h3>Option 1: Install Nginx from its official repository<\/h3>\n<p>Nginx provides an official repository contains the most recent packages for all current Ubuntu releases, so far including <strong>Ubuntu 22.04<\/strong>, <strong>Ubuntu 24.04<\/strong>, and <strong>Ubuntu 26.04<\/strong>. It&#8217;s <strong>official<\/strong> repository but contains <strong>less modules<\/strong>, and supports <code>amd64<\/code> (AMD\/Intel), <code>arm64<\/code> (e.g., Raspberry Pi and Snapdragon X), <del datetime=\"2026-05-08T08:04:19+00:00\">and <code>s390x<\/code> (IBM Z, LinuxONE)<\/del> devices.<\/p>\n<p><strong>1.<\/strong> First, open terminal (Ctrl+Alt+T) or connect to your Ubuntu Server, then run command to install required tools:<\/p>\n<pre>sudo apt install wget coreutils<\/pre>\n<p><strong>2.<\/strong> Then, download &amp; install the key file:<\/p>\n<ul>\n<li>First create <code>\/etc\/apt\/keyrings<\/code> in case it does not exist, for storing 3rd-party keys:\n<pre>sudo mkdir -p \/etc\/apt\/keyrings<\/pre>\n<\/li>\n<li>Then, use <code>wget<\/code> command to download the key, dearmor it, and finally save to the <code>\/etc\/apt\/keyrings<\/code> directory:\n<pre>sudo wget -qO - https:\/\/nginx.org\/packages\/keys\/nginx_signing.key | gpg --dearmor | sudo tee \/etc\/apt\/keyrings\/nginx_signing.gpg &gt; \/dev\/null<\/pre>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51153\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-key2604-700x444.webp\" alt=\"\" width=\"610\" height=\"387\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-key2604-700x444.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-key2604-300x190.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-key2604-768x487.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-key2604.webp 1004w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><strong>3.<\/strong> Next, run command to create &amp; edit source file:<\/p>\n<pre>sudo nano \/etc\/apt\/sources.list.d\/nginx.sources<\/pre>\n<p>When the file opens in terminal, paste following lines (for 26.04):<\/p>\n<pre>Types: deb\r\nURIs: <strong>https:\/\/nginx.org\/packages\/ubuntu\/<\/strong>\r\nSuites: <strong>resolute<\/strong>\r\nComponents: nginx\r\nArchitectures: <strong>amd64<\/strong>\r\nSigned-By: \/etc\/apt\/keyrings\/nginx_signing.key<\/pre>\n<p><strong>NOTE:<\/strong><\/p>\n<ul>\n<li>For Mainline version, use <code>https:\/\/nginx.org\/packages\/mainline\/ubuntu\/<\/code> instead for URIs.<\/li>\n<li>For other Ubuntu edition, replace <code>resolute<\/code> with <code>noble<\/code> for 24.04, or <code>jammy<\/code> for 22.04.<\/li>\n<li>For ARM devices, replace <code>amd64<\/code> with <code>arm64<\/code>.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51154\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-repo2604-700x444.webp\" alt=\"\" width=\"610\" height=\"387\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-repo2604-700x444.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-repo2604-300x190.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-repo2604-768x487.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-repo2604.webp 1004w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>Finally, press <strong>ctrl+s<\/strong> to save file, then <strong>ctrl+x<\/strong> to exit.<\/p>\n<p><strong>4.<\/strong> After setting up the key &amp; sources files, run command to refresh system package cache:<\/p>\n<pre>sudo apt update<\/pre>\n<p>In the output, there should be a line saying &#8220;Get\/Hit:x https:\/\/nginx.org\/packages\/ubuntu code-name InRelease&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51155\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/aptupdate-nginx-700x278.webp\" alt=\"\" width=\"610\" height=\"242\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/aptupdate-nginx-700x278.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/aptupdate-nginx-300x119.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/aptupdate-nginx-768x305.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/aptupdate-nginx.webp 831w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><strong>5.<\/strong> Finally, install Nginx as well as modules via command:<\/p>\n<pre>sudo apt install nginx nginx-module-*<\/pre>\n<p>As you see in the screenshot, there&#8217;s only 7 modules available. Instead of using <code>nginx-module-*<\/code> for installing all the modules, you may replace it with certain package name that you want to install.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51156\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx2604-700x475.webp\" alt=\"\" width=\"610\" height=\"414\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx2604-700x475.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx2604-300x204.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx2604-768x521.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx2604.webp 831w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><strong>NOTE:<\/strong> Installing Nginx from official repository will remove the packages (if installed) installed from Ubuntu system repository. While installing process, it may ask whether to override the original configuration file. Answer <strong>N<\/strong> (default) will keep the old one.<\/p>\n<h3>Configure Nginx<\/h3>\n<p>After installing the web server, you may run command to <strong>verify the version<\/strong>:<\/p>\n<pre>nginx -v<\/pre>\n<p>To configure it, run command to edit the config file:<\/p>\n<pre>sudo nano \/etc\/nginx\/nginx.conf<\/pre>\n<p>When the file opens in command console, you can edit the user, group, enabled modules, and other basic settings. See the <a href=\"https:\/\/nginx.org\/en\/docs\/ngx_core_module.html\" target=\"_blank\" rel=\"noopener\">official Docs<\/a> for details. <strong>NOTE: The Nginx packages were build with different user &amp; group and <code>--prefix<\/code><\/strong>.<\/p>\n<ul>\n<li><del datetime=\"2026-05-08T08:04:19+00:00\">Ubuntu and PPA packages use <code>www-data<\/code> for nginx user &amp; group, and <code>\/usr\/share\/nginx<\/code> for prefix directory.<\/del><\/li>\n<li>The official repository package use <code>nginx<\/code> for user &amp; group, and <code>\/etc\/nginx<\/code> for prefix.<\/li>\n<\/ul>\n<p>For using Nginx along with other software, such as PHP-FPM, you have to set the user (<code>www-data<\/code> or <code>nginx<\/code>) accordingly in www.conf file.<\/p>\n<div id=\"attachment_51157\" style=\"width: 620px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-51157\" class=\"size-large wp-image-51157\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/config-nginx-700x475.webp\" alt=\"\" width=\"610\" height=\"414\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/config-nginx-700x475.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/config-nginx-300x204.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/config-nginx-768x521.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/config-nginx.webp 831w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><p id=\"caption-attachment-51157\" class=\"wp-caption-text\">Nginx config file<\/p><\/div>\n<h3>Start, Restart, Troubleshot Nginx<\/h3>\n<p>After installing Nginx, it should start automatically. To verify its status, run command:<\/p>\n<pre>systemctl status nginx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51158\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-status2604-700x473.webp\" alt=\"\" width=\"610\" height=\"412\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-status2604-700x473.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-status2604-300x203.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-status2604-768x519.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-status2604.webp 773w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><br \/>\nIf it&#8217;s NOT <code>active (running)<\/code>, try enable and start it via command:<\/p>\n<pre>systemctl enable nginx<\/pre>\n<pre>systemctl start nginx<\/pre>\n<p>After making changes to Nginx config files, it&#8217;s better to run the command below to TELL if everything works:<\/p>\n<pre>nginx -t<\/pre>\n<p>Then, restart the service by running command:<\/p>\n<pre>systemctl restart nginx<\/pre>\n<p>Nginx by default enabled error log, available via <code>\/var\/log\/nginx\/error.log<\/code>. If you didn&#8217;t disable the feature in config file, then, run command to print errors if any:<\/p>\n<pre>cat \/var\/log\/nginx\/error.log |more<\/pre>\n<h3>Option 2: Install Nginx from Ubuntu PPA (DISCONTINUED)<\/h3>\n<p><b>NOTE: THIS METHOD DOES NO LONGER WORK AS THE MAINTAINER REMOVED THE PPA. Please choose Option 1 Instead!<\/b><\/p>\n<p>Ond\u0159ej Sur\u00fd, a member from <a href=\"https:\/\/nm.debian.org\/members\/\" target=\"_blank\" rel=\"noopener\">Debian developer team<\/a>, maintains very popular PPAs contain the latest mainline and stable versions of Nginx for Ubuntu 24.04, Ubuntu 22.04, and Ubuntu 20.04. The PPAs are <strong>unofficial<\/strong>, but include <strong>most modules<\/strong> and can upgrade seamlessly from the stock version in Ubuntu repository. And, it so far supports <code>amd64<\/code> (AMD\/Intel), <code>arm64\/armhf<\/code> (e.g., Raspberry Pi), and <code>ppc64el<\/code> (IBM POWER platform) devices. <strong>1.<\/strong> First, press <code>Ctrl+Alt+T<\/code> to open terminal, or connect to remote Ubuntu Server.<\/p>\n<ul>\n<li>Then, run command to make sure you have the tool to manage software repositories:\n<pre>sudo apt install software-properties-common<\/pre>\n<\/li>\n<li>To add the <a href=\"https:\/\/launchpad.net\/~ondrej\/+archive\/ubuntu\/nginx\/\" target=\"_blank\" rel=\"noopener\">Nginx Stable PPA<\/a>, run command:\n<pre>sudo add-apt-repository ppa:ondrej\/nginx<\/pre>\n<\/li>\n<li>Or, add the <a href=\"https:\/\/launchpad.net\/~ondrej\/+archive\/ubuntu\/nginx-mainline\" target=\"_blank\" rel=\"noopener\">Nginx Mainline PPA<\/a> instead via command:\n<pre>sudo add-apt-repository ppa:ondrej\/nginx-mainline<\/pre>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-ppa.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45345\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-ppa-700x475.webp\" alt=\"\" width=\"610\" height=\"414\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-ppa-700x475.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-ppa-300x204.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/nginx-ppa.webp 759w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> <strong>2.<\/strong> Ubuntu should automatically refresh package cache after adding PPA. Just in case, you may run the command below to do it manually:<\/p>\n<pre>sudo apt update<\/pre>\n<p><strong>3.<\/strong> Finally, run command to install (or upgrade from system version) nginx as well as some common used modules:<\/p>\n<pre>sudo apt install nginx-full<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45346\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full-700x460.webp\" alt=\"\" width=\"610\" height=\"401\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full-700x460.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full-300x197.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full-768x504.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-nginx-full.webp 894w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> The command will left some other modules un-installed, you may type the command below then <strong>hit Tab<\/strong> key to list all available modules:<\/p>\n<pre>sudo apt install libnginx-mod-<\/pre>\n<p><em>Then type <code>sudo apt install<\/code> plus your desired module package name to install it.<\/em> <a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45347\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods-700x474.webp\" alt=\"\" width=\"610\" height=\"413\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods-700x474.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods-300x203.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods-768x520.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/01\/apt-libnginx-mods.webp 867w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a> For choice, you may also install the <code>nginx-extras<\/code> (will replace <code>nginx-full<\/code>) that includes additional modules, such as <code>http_flv_module<\/code>, <code>http_mp4_module<\/code>, and some dynamic modules created by both Nginx and third-party developers.<\/p>\n<h3>Uninstall Nginx<\/h3>\n<p>If you want to remove Nginx from your machine or server, run command to disable the service first:<\/p>\n<pre>systemctl disable --now nginx<\/pre>\n<p>Then remove the nginx packages:<\/p>\n<pre>sudo apt remove --autoremove nginx nginx-module-*<\/pre>\n<p>And, remove the official repository by deleting the sources and key files:<\/p>\n<pre>sudo rm \/etc\/apt\/keyrings\/nginx_signing.gpg \/etc\/apt\/sources.list.d\/nginx.sources<\/pre>\n<p>Finally, run <code>sudo apt update<\/code> to refresh system package cache.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is a step by step beginner&#8217;s guide shows how to install the latest version of Nginx web server (either mainline or stable) in Ubuntu 26.04, Ubuntu 24.04, or Ubuntu 22.04 Desktop or Server. Nginx is a popular free and open-source web server, that can be also used as reverse proxy, load balancer, mail proxy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":45344,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[748,2057],"class_list":["post-45343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-nginx","tag-web"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=45343"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/45344"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=45343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=45343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=45343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}