<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Install Nginx on Ubuntu Tutorial]]></title><description><![CDATA[<p dir="auto">This tutorial provides a step-by-step guide to installing and configuring the Nginx web server on Ubuntu. Nginx is a high-performance web server known for its stability, rich feature set, and low resource consumption.</p>
<p dir="auto"><strong>Prerequisites</strong><br />
To follow this guide, you will need:</p>
<ul>
<li>An Ubuntu server (version 22.04 or later is recommended).</li>
<li>A non-root user with sudo privileges configured on your server.</li>
<li>A basic understanding of the Linux command line.</li>
</ul>
<h2>Step 1: Installing Nginx</h2>
<p dir="auto">Nginx is available in Ubuntu’s default software repositories. This means you can use the <code>apt</code> package management system to install it.</p>
<p dir="auto">First, update your local package index to ensure you have the latest metadata:</p>
<pre><code>sudo apt update
</code></pre>
<p dir="auto">Next, install the Nginx package:</p>
<pre><code>sudo apt install nginx
</code></pre>
<p dir="auto">After the installation is complete, Nginx will start automatically. You can verify the installed version by typing:</p>
<pre><code class="language-bash">nginx -v
</code></pre>
<h2>Step 2: Adjusting the Firewall</h2>
<p dir="auto">Before you can access your web server, you must adjust your firewall settings to allow external access to the default web ports. Nginx registers itself with ufw (Uncomplicated Firewall) upon installation.</p>
<p dir="auto">List the available application profiles:</p>
<pre><code>sudo ufw app list
</code></pre>
<p dir="auto">You will see several Nginx profiles:</p>
<ul>
<li><strong>Nginx Full</strong> : Opens port 80 (HTTP) and port 443 (HTTPS).</li>
<li><strong>Nginx HTTP</strong> : Opens only port 80.</li>
<li><strong>Nginx HTTPS</strong> : Opens only port 443.</li>
</ul>
<p dir="auto">For a fresh installation without an SSL certificate, enable the HTTP profile:</p>
<pre><code>sudo ufw allow 'Nginx HTTP'
</code></pre>
<p dir="auto">Verify the status of the firewall:</p>
<pre><code>sudo ufw status
</code></pre>
<h2>Step 3: Checking your Web Server</h2>
<p dir="auto">At the end of the installation process, Ubuntu starts Nginx automatically. You can verify that the service is active and running using <code>systemd</code>:</p>
<pre><code>systemctl status nginx
</code></pre>
<p dir="auto">To confirm the server is accessible over the network, visit your server’s IP address in your web browser. If you don't know your server's public IP, you can find it via the command line:</p>
<pre><code>curl -4 icanhazip.com
</code></pre>
<p dir="auto">Type the IP address you receive into your web browser:<br />
<code>http://your_server_ip</code></p>
<p dir="auto">You should see the default <strong>"Welcome to nginx!"</strong> landing page, which confirms the software is running correctly.</p>
<h2>Step 4: Managing the Nginx Process</h2>
<p dir="auto">Now that the web server is up and running, here are some basic management commands:</p>
<ul>
<li><strong>Stop Nginx</strong> : <code>sudo systemctl stop nginx</code></li>
<li><strong>Start Nginx</strong> : <code>sudo systemctl start nginx</code></li>
<li><strong>Restart Nginx</strong> : <code>sudo systemctl restart nginx</code></li>
<li><strong>Reload Nginx (apply config changes without dropping connections)</strong> : <code>sudo systemctl reload nginx</code></li>
<li><strong>Disable Nginx from starting at server boot</strong> : <code>sudo systemctl disable nginx</code></li>
<li><strong>Enable Nginx to start at server boot (default behavior)</strong> : <code>sudo systemctl enable nginx</code></li>
</ul>
<h2>Step 5: Setting Up Server Blocks (Recommended)</h2>
<p dir="auto">Server blocks allow you to host more than one domain from a single Nginx server. While the default configuration serves content from <code>/var/www/html</code>, it is better practice to create a separate directory structure for each site.</p>
<p dir="auto"><strong>1. Create the directory for your domain:</strong><br />
Leave the default <code>/var/www/html</code> directory intact and create a new directory for your domain:</p>
<pre><code>sudo mkdir -p /var/www/your_domain/html
</code></pre>
<p dir="auto"><strong>2. Assign ownership of the directory:</strong></p>
<pre><code>sudo chown -R $USER:$USER /var/www/your_domain/html
</code></pre>
<p dir="auto"><strong>3. Ensure correct permissions:</strong></p>
<pre><code>sudo chmod -R 755 /var/www/your_domain
</code></pre>
<p dir="auto"><strong>4. Create a sample <code>index.html</code> page:</strong><br />
Open a new file using your preferred text editor (like <code>nano</code>) :</p>
<pre><code>nano /var/www/your_domain/html/index.html
</code></pre>
<p dir="auto">Paste the following HTML into the file, then save and exit:</p>
<pre><code class="language-html">&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Welcome to your_domain!&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Success! The your_domain server block is working!&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p dir="auto"><strong>5. Create a new server block configuration file:</strong></p>
<pre><code>sudo nano /etc/nginx/sites-available/your_domain
</code></pre>
<p dir="auto">Paste the following configuration, ensuring you update the <code>server_name</code> to match your domain:</p>
<pre><code>server {
    listen 80;
    listen [::]:80;

    root /var/www/your_domain/html;
    index index.html index.htm;

    server_name your_domain www.your_domain;

    location / {
        try_files $uri $uri/ =404;
    }
}
</code></pre>
<p dir="auto">Save and exit the file.</p>
<p dir="auto"><strong>6. Enable the new server block:</strong></p>
<p dir="auto">Create a symbolic link from your file to the <code>sites-enabled</code> directory:</p>
<pre><code>sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
</code></pre>
<p dir="auto"><strong>7. Resolve potential hash bucket memory issues:</strong></p>
<p dir="auto">Open the main Nginx configuration file:</p>
<pre><code>sudo nano /etc/nginx/nginx.conf
</code></pre>
<p dir="auto">Find the <code>server_names_hash_bucket_size</code> directive and remove the <code>#</code> symbol to uncomment it. Save and exit.</p>
<p dir="auto"><strong>8. Test and Restart Nginx:</strong></p>
<p dir="auto">Test your configuration files for syntax errors:</p>
<pre><code>sudo nginx -t
</code></pre>
<p dir="auto">If the test is successful, restart Nginx to apply your changes:</p>
<pre><code>sudo systemctl restart nginx
</code></pre>
<p dir="auto">Nginx should now be serving your new domain name. You can test this by navigating to <code>http://your_domain</code>, where you should see the success page you created in step 4.</p>
]]></description><link>https://ivan9.com/topic/2/install-nginx-on-ubuntu-tutorial</link><generator>RSS for Node</generator><lastBuildDate>Sun, 03 May 2026 06:13:31 GMT</lastBuildDate><atom:link href="https://ivan9.com/topic/2.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Mar 2026 14:43:14 GMT</pubDate><ttl>60</ttl></channel></rss>