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.
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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 theerror_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
Heya @lukemccartney,
here is an example nginx block on port 80:
server { listen 80; listen [::]:80;
}
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?
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
Update Package Lists: Always start by updating your package lists to ensure you’re getting the latest versions of software available.
Install NGINX:
Check NGINX Status: After installation, NGINX should start automatically. You can check its status with:
If NGINX isn’t running, you can start it with:
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/
.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, forexample.com
:Create a Sample HTML Page: This is just to test that the server block works.
Create Server Block File: Copy the default server block as a starting point for your site.
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:Enable the Server Block: Create a symbolic link to the
sites-enabled
directory.Test NGINX Configuration: Before restarting NGINX, check for syntax errors in any of your NGINX configuration files.
Restart NGINX: Apply the changes by restarting NGINX.
If you have UFW (Uncomplicated Firewall) enabled, ensure it allows traffic to NGINX.
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