Question

Will setting up NGINX be updated for Ubuntu 23?

As I was following the guide for installing Nginx on Ubuntu 22.04 (https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-22-04) I noticed that the server blocks no longer work and default is used always.

I think I followed everything correctly but I still just get greeted with the ‘Welcome to NGINX’ page every time.

I’m currently using Ubuntu 23.10.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
February 22, 2024

Heya, @lukemccartney

The process for setting NGINX server bloks on Ubuntu 23 should be quite similar to setting this on a 22.04 droplet.

You can check the NGINX configuration (use - nginx -t) for any errors and examine the error_log as well.

I believe that by default the index.html file might be prioritised instead of index.php and etc. In this case you can check the default index file in the NGINX server block.

If SSL is needed you can check this article:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-22-04

Regards

KFSys
Site Moderator
Site Moderator badge
February 22, 2024

Heya @lukemccartney,

here is an example nginx block on port 80:

server { listen 80; listen [::]:80;

root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;

server_name example.com www.example.com;

location / {
    try_files $uri $uri/ =404;
}

}


That will open the file `/var/www/example.com/html/index.html` when (in this case) example.com is loaded. 
Bobby Iliev
Site Moderator
Site Moderator badge
February 22, 2024

Hey!

Installing NGINX on Ubuntu 23.10 and configuring server blocks should be quite similar or nearly identical to the process on Ubuntu 22.04.

Do you see any errors in the Nginx error log?

tail -100 /var/log/nginx/error.log

In general, here’s how you can go about installing NGINX on Ubuntu 23.10 and setting up server blocks to serve different content for different domain names hosted on the same server.

Step 1: Install NGINX

  1. Update Package Lists: Always start by updating your package lists to ensure you’re getting the latest versions of software available.

    sudo apt update
    
  2. Install NGINX:

    sudo apt install nginx
    
  3. Check NGINX Status: After installation, NGINX should start automatically. You can check its status with:

    sudo systemctl status nginx
    

    If NGINX isn’t running, you can start it with:

    sudo systemctl start nginx
    

Step 2: Configure NGINX Server Blocks

Ubuntu 23.10 should follow the same structure for NGINX configuration as Ubuntu 22.04, with server block files located in /etc/nginx/sites-available/ and enabled by creating a symbolic link in /etc/nginx/sites-enabled/.

  1. Create a Directory for Your Site: For organizational purposes, it’s a good idea to create a directory under /var/www/ for each domain. For example, for example.com:

    sudo mkdir -p /var/www/example.com/html
    sudo chown -R www-data:www-data /var/www/example.com/html
    sudo chmod -R 755 /var/www
    
  2. Create a Sample HTML Page: This is just to test that the server block works.

    echo "<html>
    <head>
    <title>Welcome to Example.com!</title>
    </head>
    <body>
    <h1>Success! The Example.com server block is working!</h1>
    </body>
    </html>" | sudo tee /var/www/example.com/html/index.html
    
  3. Create Server Block File: Copy the default server block as a starting point for your site.

    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
    
  4. Edit the Server Block File: Modify /etc/nginx/sites-available/example.com to serve your site. Open it in a text editor and update it to look something like this:

    server {
        listen 80;
        listen [::]:80;
    
        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;
    
        server_name example.com www.example.com;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
    
  5. Enable the Server Block: Create a symbolic link to the sites-enabled directory.

    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
    
  6. Test NGINX Configuration: Before restarting NGINX, check for syntax errors in any of your NGINX configuration files.

    sudo nginx -t
    
  7. Restart NGINX: Apply the changes by restarting NGINX.

    sudo systemctl restart nginx
    

If you have UFW (Uncomplicated Firewall) enabled, ensure it allows traffic to NGINX.

sudo ufw allow 'Nginx Full'

Now, when you navigate to http://example.com, you should see your custom page instead of the default NGINX welcome page. If you still encounter the default page, ensure you’ve cleared your browser’s cache or try accessing the site using a different browser or incognito mode to avoid cached redirects.

Note that when using actual domain names, you need to point your domain’s DNS records to the server’s IP address where NGINX is installed.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel