SlideShare a Scribd company logo
1/9
February 12, 2025
How to Set Up Nginx Server Blocks on Ubuntu 24.04
greenwebpage.com/community/how-to-set-up-nginx-server-blocks-on-ubuntu-24-04/
Tutorials
by Karim Buzdar
February 12, 2025
Nginx is a leading web server choice renowned for its efficiency, versatility, and stability.
By leveraging Nginx’s ability to handle high-traffic loads and act as a reverse proxy, you
can significantly enhance website performance and scalability. We’ll cover the essential
steps, from installing Nginx and organizing website files to configuring server blocks for
different domains or subdomains. This guide will walk you through setting up multiple
websites on a single Ubuntu 24.04 server using Nginx server blocks.
Let’s dive into the process of building a robust Nginx web server environment.
Prerequisite: Installing Nginx on Ubuntu 24.04
Setting Up Nginx Server Blocks on Ubuntu 24.04
Prerequisite: Installing Nginx on Ubuntu 24.04
For those running Ubuntu and seeking a robust web server solution, Nginx is an excellent
option. Follow these steps to install it:
Step 1: Update Package Lists
2/9
Start by synchronizing your package lists with the most current repository data:
sudo apt update
Step 2: Install Nginx
Nginx can be obtained through the apt package manager by running the appropriate
command as superuser if it’s not already installed on the system:
sudo apt install nginx
Step 3: Adjust the Firewall
To ensure the website is accessible, users need to configure the firewall. It allows traffic to
the Nginx web server. If you’re using UFW, you can easily do this.
Nginx offers three primary settings to manage incoming web traffic:
Full Access: Permits both standard (HTTP) and secure (HTTPS) connections on ports
80 and 443, respectively.
HTTP Only: Allows only standard web traffic on port 80.
HTTPS Only: Enables secure web traffic exclusively on port 443.
Choose the setting that best suits your website’s requirements. To activate your chosen
configuration, use the following command:
sudo ufw allow 'Nginx HTTP'
3/9
To authenticate the status of the Firewall, users can utilize the “ufw” tool:
sudo ufw status
Step 4: Managing Nginx (Optional)
As a widely popular choice for hosting websites, Nginx can be efficiently managed using
these commands:
4/9
Managing Nginx Services Commands
For Enabling Nginx to Start on the Boot sudo systemctl enable nginx
For Enabling Firewall sudo ufw enable
For Enlisting Installed Applications sudo ufw app list
For Starting the Nginx Service sudo systemctl start nginx
For Stopping Nginx Service sudo systemctl stop nginx
For Restarting the Nginx Service sudo systemctl restart nginx
Step 5: Verify the Installation
To verify Nginx is operational following installation, execute the command:
sudo systemctl status nginx
Step 6: Access Nginx Page
To access the Nginx web page, users can either input “localhost” or the specific IP
address of the Ubuntu server, which is currently 10.0.2.15:
5/9
That is all from the installation of Nginx on Ubuntu 24.04.
Setting Up Nginx Server Blocks on Ubuntu 24.04
Configuring Nginx server blocks on Ubuntu 24.04 is a multi-step process that establishes
distinct environments for each hosted domain. Follow these steps to set up your Nginx
server blocks:
Step 1: Create Directory Structure
Each hosted website requires its own dedicated folder to store its files. For optimal
organization, create separate folders within the “/var/www/” directory for each domain.
When setting up Nginx, establish a folder structure under “/var/www/” for your websites.
Each domain should have its own “html” subdirectory designated as the document root:
sudo mkdir -p /var/www/linux.com/html
Important: Users can replace “linux.com” with the domain name.
Step 2: Assign Ownership
Assigning ownership of the directory to the Nginx user (usually ‘www-data’) is crucial for
avoiding permission-related errors:
sudo chown -R $USER:$USER /var/www/linux.com/html
6/9
Step 3: Set File Permission
To set permissions, users should employ the chmod -R command on the desired path:
sudo chmod -R 755 /var/www/linux.com
Step 4: Create an HTML file
Once file permissions are set, create an HTML page (e.g., “index.html“) in the
“/var/www/linux.com/html/” directory:
sudo nano /var/www/linux.com/html/index.html
Users need to paste the HTML code in the configuration file:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Linux empowers the Ubuntu Users</title>
</head>
<body>
<h1> Setting Up Nginx Server Blocks on Ubuntu 24.04 </h1>
</body>
</html>
In the end, save and exit the file.
Step 5: Create Server Blocks
Just like Apache’s virtual hosts, Nginx employs server blocks to define specific settings
for different domains or subdomains hosted on the same server:
sudo nano /etc/nginx/sites-available/linux.com
7/9
This script configures your web server to handle requests for the website “linux.com”. It
listens on the standard port 80 and delivers files from the directory you specify:
server {
listen 80;
listen [::]:80;
root /var/www/linux.com/html;
index index.html index.htm index.nginx-debian.html;
server_name linux.com www.linux.com;
location / {
try_files $uri $uri/ =404;
}
}
So, save and exit the configuration file.
Note: These configuration files define the specific settings for each domain, such as the
server’s identity, primary content directory, and paths to access and error logs.
Step 6: Enable Server Blocks
After creating server block configurations, users need to enable them by linking the files
to the ‘sites-enabled‘ folder:
sudo ln -s /etc/nginx/sites-available/linux.com /etc/nginx/sites-enabled/
8/9
Important: Users can perform this step for each server block.
Step 7: Test and Restart Nginx
To prevent potential issues, it’s crucial to check the recently modified Nginx configuration
for accuracy before initiating the service. This can be easily accomplished by executing
the ‘nginx -t’ command:
sudo nginx -t
Step 8: Restart Nginx
Now, the configuration changes can be activated by restarting Nginx with the ‘systemctl’
command:
sudo systemctl restart nginx
Note: To access your Nginx server, your firewall must be configured to permit incoming
connections on ports 80 for HTTP and 443 for HTTPS.
Step 9: Verify Nginx Setup
To complete the process, ensure your websites are accessible by opening a web browser
and entering localhost/domain_names/IP_address in the address bar:
In this way, Nginx server blocks have been set up on the Ubuntu 24.04 server.
Conclusion
Configuring Nginx server blocks on Ubuntu involves several essential steps. Begin by
establishing dedicated directories within /var/www for each website, ensuring proper
permissions. Next, craft detailed server block configurations within the /etc/nginx/sites-
9/9
available directory, outlining how Nginx should handle requests for each domain.
To activate these configurations, create symbolic links in the /etc/nginx/sites-enabled
folder. Before deploying changes, it’s crucial to thoroughly test the configuration for errors
to guarantee optimal performance.
Frequently Asked Questions
What are Nginx server blocks?
Nginx server blocks, also known as virtual hosts, allow you to host multiple websites on a
single server by creating separate configurations for each site.
How do I install Nginx on Ubuntu 24.04?
To install Nginx, run sudo apt update and then sudo apt install nginx. Once
installed, Nginx can be started with sudo systemctl start nginx.
How do I create a new server block?
Create a new configuration file in the /etc/nginx/sites-available/ directory and then
create a symbolic link in /etc/nginx/sites-enabled/ to activate it.
How do I configure a server block for a domain?
Edit the configuration file for your domain in /etc/nginx/sites-
available/yourdomain.com with the correct server name, root directory, and other
settings, then create a symbolic link in sites-enabled.
How do I test the Nginx configuration?
Run sudo nginx -t to check for syntax errors in the configuration files before reloading
Nginx.

More Related Content

Similar to How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf (20)

How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
RootGate
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
Sarah Novotny
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
VEXXHOST Private Cloud
 
A Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container PlatformsA Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container Platforms
Salman Baset
 
Diva23
Diva23Diva23
Diva23
diva23
 
Practical solutions for connections administrators
Practical solutions for connections administratorsPractical solutions for connections administrators
Practical solutions for connections administrators
Sharon James
 
Ubuntu vps setup
Ubuntu vps setupUbuntu vps setup
Ubuntu vps setup
Vijay Sharma
 
Apache
ApacheApache
Apache
rsibbaluca
 
Apache
ApacheApache
Apache
rsibbaluca
 
Apache
ApacheApache
Apache
rsibbaluca
 
Apache
ApacheApache
Apache
Rathan Raj
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
Cohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive networks Support Docs: VNS3:turret WAF GuideCohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive Networks
 
Apache
ApacheApache
Apache
NIRMAL FELIX
 
NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)
Marcel Cattaneo
 
Install and configure linux
Install and configure linuxInstall and configure linux
Install and configure linux
Vicent Selfa
 
Sa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administratorsSa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administrators
Sharon James
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
RootGate
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
Sarah Novotny
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
VEXXHOST Private Cloud
 
A Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container PlatformsA Survey of Container Security in 2016: A Security Update on Container Platforms
A Survey of Container Security in 2016: A Security Update on Container Platforms
Salman Baset
 
Diva23
Diva23Diva23
Diva23
diva23
 
Practical solutions for connections administrators
Practical solutions for connections administratorsPractical solutions for connections administrators
Practical solutions for connections administrators
Sharon James
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
Cohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive networks Support Docs: VNS3:turret WAF GuideCohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive networks Support Docs: VNS3:turret WAF Guide
Cohesive Networks
 
NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)
Marcel Cattaneo
 
Install and configure linux
Install and configure linuxInstall and configure linux
Install and configure linux
Vicent Selfa
 
Sa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administratorsSa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administrators
Sharon James
 

More from Green Webpage (20)

How to Install Portainer Docker UI Web Interface on Debian 12.pdf
How to Install Portainer Docker UI Web Interface on Debian 12.pdfHow to Install Portainer Docker UI Web Interface on Debian 12.pdf
How to Install Portainer Docker UI Web Interface on Debian 12.pdf
Green Webpage
 
How to Install Java on Debian 12 Using Apt and Deb.pdf
How to Install Java on Debian 12 Using Apt and Deb.pdfHow to Install Java on Debian 12 Using Apt and Deb.pdf
How to Install Java on Debian 12 Using Apt and Deb.pdf
Green Webpage
 
How to Install iptable on Debian 12.docx
How to Install iptable on Debian 12.docxHow to Install iptable on Debian 12.docx
How to Install iptable on Debian 12.docx
Green Webpage
 
How to Install Proxmox on Debian 12_ .docx
How to Install Proxmox on Debian 12_ .docxHow to Install Proxmox on Debian 12_ .docx
How to Install Proxmox on Debian 12_ .docx
Green Webpage
 
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
How to Install MySQL on Debian 12 In Just 8 Steps.pdfHow to Install MySQL on Debian 12 In Just 8 Steps.pdf
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
Green Webpage
 
How to Install NFS Server and Client on Ubuntu 2404.pdf
How to Install NFS Server and Client on Ubuntu 2404.pdfHow to Install NFS Server and Client on Ubuntu 2404.pdf
How to Install NFS Server and Client on Ubuntu 2404.pdf
Green Webpage
 
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdfHow to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
Green Webpage
 
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdfHow to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
Green Webpage
 
How to Install Docker on Debian 12 All Possible Methods.pdf
How to Install Docker on Debian 12 All Possible Methods.pdfHow to Install Docker on Debian 12 All Possible Methods.pdf
How to Install Docker on Debian 12 All Possible Methods.pdf
Green Webpage
 
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdfHow to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
Green Webpage
 
How to Install XFCE Desktop on Ubuntu 2404.pdf
How to Install XFCE Desktop on Ubuntu 2404.pdfHow to Install XFCE Desktop on Ubuntu 2404.pdf
How to Install XFCE Desktop on Ubuntu 2404.pdf
Green Webpage
 
How to Install MariaDB on Ubuntu 2404.pdf
How to Install MariaDB on Ubuntu 2404.pdfHow to Install MariaDB on Ubuntu 2404.pdf
How to Install MariaDB on Ubuntu 2404.pdf
Green Webpage
 
How to Check and Update the Python Version on Ubuntu 2404.pdf
How to Check and Update the Python Version on Ubuntu 2404.pdfHow to Check and Update the Python Version on Ubuntu 2404.pdf
How to Check and Update the Python Version on Ubuntu 2404.pdf
Green Webpage
 
How to Add Comments to Iptable Rules 6 Examples.pdf
How to Add Comments to Iptable Rules 6 Examples.pdfHow to Add Comments to Iptable Rules 6 Examples.pdf
How to Add Comments to Iptable Rules 6 Examples.pdf
Green Webpage
 
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdfHow to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
Green Webpage
 
How to Install and Manage Podman on Ubuntu 2404.pdf
How to Install and Manage Podman on Ubuntu 2404.pdfHow to Install and Manage Podman on Ubuntu 2404.pdf
How to Install and Manage Podman on Ubuntu 2404.pdf
Green Webpage
 
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdfHow to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
Green Webpage
 
How to Install and Use Docker Compose on Ubuntu 2404.pdf
How to Install and Use Docker Compose on Ubuntu 2404.pdfHow to Install and Use Docker Compose on Ubuntu 2404.pdf
How to Install and Use Docker Compose on Ubuntu 2404.pdf
Green Webpage
 
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdfHow to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
Green Webpage
 
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdfHow to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
Green Webpage
 
How to Install Portainer Docker UI Web Interface on Debian 12.pdf
How to Install Portainer Docker UI Web Interface on Debian 12.pdfHow to Install Portainer Docker UI Web Interface on Debian 12.pdf
How to Install Portainer Docker UI Web Interface on Debian 12.pdf
Green Webpage
 
How to Install Java on Debian 12 Using Apt and Deb.pdf
How to Install Java on Debian 12 Using Apt and Deb.pdfHow to Install Java on Debian 12 Using Apt and Deb.pdf
How to Install Java on Debian 12 Using Apt and Deb.pdf
Green Webpage
 
How to Install iptable on Debian 12.docx
How to Install iptable on Debian 12.docxHow to Install iptable on Debian 12.docx
How to Install iptable on Debian 12.docx
Green Webpage
 
How to Install Proxmox on Debian 12_ .docx
How to Install Proxmox on Debian 12_ .docxHow to Install Proxmox on Debian 12_ .docx
How to Install Proxmox on Debian 12_ .docx
Green Webpage
 
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
How to Install MySQL on Debian 12 In Just 8 Steps.pdfHow to Install MySQL on Debian 12 In Just 8 Steps.pdf
How to Install MySQL on Debian 12 In Just 8 Steps.pdf
Green Webpage
 
How to Install NFS Server and Client on Ubuntu 2404.pdf
How to Install NFS Server and Client on Ubuntu 2404.pdfHow to Install NFS Server and Client on Ubuntu 2404.pdf
How to Install NFS Server and Client on Ubuntu 2404.pdf
Green Webpage
 
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdfHow to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
Green Webpage
 
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdfHow to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
How to Set Static IP Address on Ubuntu 2404 4 Possible Methods.pdf
Green Webpage
 
How to Install Docker on Debian 12 All Possible Methods.pdf
How to Install Docker on Debian 12 All Possible Methods.pdfHow to Install Docker on Debian 12 All Possible Methods.pdf
How to Install Docker on Debian 12 All Possible Methods.pdf
Green Webpage
 
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdfHow to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
How to Add Users to Sudoers on Debian 12 Complete Tutorial.pdf
Green Webpage
 
How to Install XFCE Desktop on Ubuntu 2404.pdf
How to Install XFCE Desktop on Ubuntu 2404.pdfHow to Install XFCE Desktop on Ubuntu 2404.pdf
How to Install XFCE Desktop on Ubuntu 2404.pdf
Green Webpage
 
How to Install MariaDB on Ubuntu 2404.pdf
How to Install MariaDB on Ubuntu 2404.pdfHow to Install MariaDB on Ubuntu 2404.pdf
How to Install MariaDB on Ubuntu 2404.pdf
Green Webpage
 
How to Check and Update the Python Version on Ubuntu 2404.pdf
How to Check and Update the Python Version on Ubuntu 2404.pdfHow to Check and Update the Python Version on Ubuntu 2404.pdf
How to Check and Update the Python Version on Ubuntu 2404.pdf
Green Webpage
 
How to Add Comments to Iptable Rules 6 Examples.pdf
How to Add Comments to Iptable Rules 6 Examples.pdfHow to Add Comments to Iptable Rules 6 Examples.pdf
How to Add Comments to Iptable Rules 6 Examples.pdf
Green Webpage
 
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdfHow to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
How to Limit CPU Usage of a Process in Linux with CPULimit With Examples.pdf
Green Webpage
 
How to Install and Manage Podman on Ubuntu 2404.pdf
How to Install and Manage Podman on Ubuntu 2404.pdfHow to Install and Manage Podman on Ubuntu 2404.pdf
How to Install and Manage Podman on Ubuntu 2404.pdf
Green Webpage
 
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdfHow to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
How to Install Apache Cassandra on Ubuntu 2404 Top 3 Ways.pdf
Green Webpage
 
How to Install and Use Docker Compose on Ubuntu 2404.pdf
How to Install and Use Docker Compose on Ubuntu 2404.pdfHow to Install and Use Docker Compose on Ubuntu 2404.pdf
How to Install and Use Docker Compose on Ubuntu 2404.pdf
Green Webpage
 
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdfHow to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
How to Find Motherboard Model and Serial Number in Linux 3 Methods.pdf
Green Webpage
 
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdfHow to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
How to Install Eclipse IDE on Ubuntu 2404 3 Quick Methods.pdf
Green Webpage
 
Ad

Recently uploaded (20)

Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Ad

How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf

  • 1. 1/9 February 12, 2025 How to Set Up Nginx Server Blocks on Ubuntu 24.04 greenwebpage.com/community/how-to-set-up-nginx-server-blocks-on-ubuntu-24-04/ Tutorials by Karim Buzdar February 12, 2025 Nginx is a leading web server choice renowned for its efficiency, versatility, and stability. By leveraging Nginx’s ability to handle high-traffic loads and act as a reverse proxy, you can significantly enhance website performance and scalability. We’ll cover the essential steps, from installing Nginx and organizing website files to configuring server blocks for different domains or subdomains. This guide will walk you through setting up multiple websites on a single Ubuntu 24.04 server using Nginx server blocks. Let’s dive into the process of building a robust Nginx web server environment. Prerequisite: Installing Nginx on Ubuntu 24.04 Setting Up Nginx Server Blocks on Ubuntu 24.04 Prerequisite: Installing Nginx on Ubuntu 24.04 For those running Ubuntu and seeking a robust web server solution, Nginx is an excellent option. Follow these steps to install it: Step 1: Update Package Lists
  • 2. 2/9 Start by synchronizing your package lists with the most current repository data: sudo apt update Step 2: Install Nginx Nginx can be obtained through the apt package manager by running the appropriate command as superuser if it’s not already installed on the system: sudo apt install nginx Step 3: Adjust the Firewall To ensure the website is accessible, users need to configure the firewall. It allows traffic to the Nginx web server. If you’re using UFW, you can easily do this. Nginx offers three primary settings to manage incoming web traffic: Full Access: Permits both standard (HTTP) and secure (HTTPS) connections on ports 80 and 443, respectively. HTTP Only: Allows only standard web traffic on port 80. HTTPS Only: Enables secure web traffic exclusively on port 443. Choose the setting that best suits your website’s requirements. To activate your chosen configuration, use the following command: sudo ufw allow 'Nginx HTTP'
  • 3. 3/9 To authenticate the status of the Firewall, users can utilize the “ufw” tool: sudo ufw status Step 4: Managing Nginx (Optional) As a widely popular choice for hosting websites, Nginx can be efficiently managed using these commands:
  • 4. 4/9 Managing Nginx Services Commands For Enabling Nginx to Start on the Boot sudo systemctl enable nginx For Enabling Firewall sudo ufw enable For Enlisting Installed Applications sudo ufw app list For Starting the Nginx Service sudo systemctl start nginx For Stopping Nginx Service sudo systemctl stop nginx For Restarting the Nginx Service sudo systemctl restart nginx Step 5: Verify the Installation To verify Nginx is operational following installation, execute the command: sudo systemctl status nginx Step 6: Access Nginx Page To access the Nginx web page, users can either input “localhost” or the specific IP address of the Ubuntu server, which is currently 10.0.2.15:
  • 5. 5/9 That is all from the installation of Nginx on Ubuntu 24.04. Setting Up Nginx Server Blocks on Ubuntu 24.04 Configuring Nginx server blocks on Ubuntu 24.04 is a multi-step process that establishes distinct environments for each hosted domain. Follow these steps to set up your Nginx server blocks: Step 1: Create Directory Structure Each hosted website requires its own dedicated folder to store its files. For optimal organization, create separate folders within the “/var/www/” directory for each domain. When setting up Nginx, establish a folder structure under “/var/www/” for your websites. Each domain should have its own “html” subdirectory designated as the document root: sudo mkdir -p /var/www/linux.com/html Important: Users can replace “linux.com” with the domain name. Step 2: Assign Ownership Assigning ownership of the directory to the Nginx user (usually ‘www-data’) is crucial for avoiding permission-related errors: sudo chown -R $USER:$USER /var/www/linux.com/html
  • 6. 6/9 Step 3: Set File Permission To set permissions, users should employ the chmod -R command on the desired path: sudo chmod -R 755 /var/www/linux.com Step 4: Create an HTML file Once file permissions are set, create an HTML page (e.g., “index.html“) in the “/var/www/linux.com/html/” directory: sudo nano /var/www/linux.com/html/index.html Users need to paste the HTML code in the configuration file: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Linux empowers the Ubuntu Users</title> </head> <body> <h1> Setting Up Nginx Server Blocks on Ubuntu 24.04 </h1> </body> </html> In the end, save and exit the file. Step 5: Create Server Blocks Just like Apache’s virtual hosts, Nginx employs server blocks to define specific settings for different domains or subdomains hosted on the same server: sudo nano /etc/nginx/sites-available/linux.com
  • 7. 7/9 This script configures your web server to handle requests for the website “linux.com”. It listens on the standard port 80 and delivers files from the directory you specify: server { listen 80; listen [::]:80; root /var/www/linux.com/html; index index.html index.htm index.nginx-debian.html; server_name linux.com www.linux.com; location / { try_files $uri $uri/ =404; } } So, save and exit the configuration file. Note: These configuration files define the specific settings for each domain, such as the server’s identity, primary content directory, and paths to access and error logs. Step 6: Enable Server Blocks After creating server block configurations, users need to enable them by linking the files to the ‘sites-enabled‘ folder: sudo ln -s /etc/nginx/sites-available/linux.com /etc/nginx/sites-enabled/
  • 8. 8/9 Important: Users can perform this step for each server block. Step 7: Test and Restart Nginx To prevent potential issues, it’s crucial to check the recently modified Nginx configuration for accuracy before initiating the service. This can be easily accomplished by executing the ‘nginx -t’ command: sudo nginx -t Step 8: Restart Nginx Now, the configuration changes can be activated by restarting Nginx with the ‘systemctl’ command: sudo systemctl restart nginx Note: To access your Nginx server, your firewall must be configured to permit incoming connections on ports 80 for HTTP and 443 for HTTPS. Step 9: Verify Nginx Setup To complete the process, ensure your websites are accessible by opening a web browser and entering localhost/domain_names/IP_address in the address bar: In this way, Nginx server blocks have been set up on the Ubuntu 24.04 server. Conclusion Configuring Nginx server blocks on Ubuntu involves several essential steps. Begin by establishing dedicated directories within /var/www for each website, ensuring proper permissions. Next, craft detailed server block configurations within the /etc/nginx/sites-
  • 9. 9/9 available directory, outlining how Nginx should handle requests for each domain. To activate these configurations, create symbolic links in the /etc/nginx/sites-enabled folder. Before deploying changes, it’s crucial to thoroughly test the configuration for errors to guarantee optimal performance. Frequently Asked Questions What are Nginx server blocks? Nginx server blocks, also known as virtual hosts, allow you to host multiple websites on a single server by creating separate configurations for each site. How do I install Nginx on Ubuntu 24.04? To install Nginx, run sudo apt update and then sudo apt install nginx. Once installed, Nginx can be started with sudo systemctl start nginx. How do I create a new server block? Create a new configuration file in the /etc/nginx/sites-available/ directory and then create a symbolic link in /etc/nginx/sites-enabled/ to activate it. How do I configure a server block for a domain? Edit the configuration file for your domain in /etc/nginx/sites- available/yourdomain.com with the correct server name, root directory, and other settings, then create a symbolic link in sites-enabled. How do I test the Nginx configuration? Run sudo nginx -t to check for syntax errors in the configuration files before reloading Nginx.