
Nginx is a free and open-source web server software that facilitates the hosting of static and dynamic web applications or services on your server. It can function as a web server, load balancer, reverse proxy, or HTTP cache, enabling integration with other applications to form a complete stack or to serve web applications through your server’s IP address or domain.
This article explains the process for installing Nginx on Ubuntu 25.04 and configuring sample web applications to ensure optimal performance on your server.
Before you begin, you need to:
app.example.com.Nginx is included in the default APT repositories for Ubuntu 25.04. To install the latest version of Nginx, follow the steps below to update your server's package list and install the web server.
Update the package index on your server.
Install the Nginx web server.
View the installed version of Nginx web server.
Your output should be similar to the one below:
Nginx operates as a systemd service on Ubuntu, which allows you to control its processes and manage its runtime. Follow the steps below to enable the nginx service start automatically on boot and control the Nginx system service.
Enable the Nginx service to start automatically on boot.
Your output should be similar to the one below:
Start the Nginx service.
Stop the Nginx service.
Restart the Nginx service.
View the status of the Nginx service to confirm it's running.
Your output should be similar to the one below:
Based on the output value Active: active (running), Nginx is running on your server. If the service status shows Active: active (failed), it indicates an issue. In such cases, stop any processes currently occupying HTTP port 80 and then restart the Nginx service to resolve the issue.
Nginx virtual hosts allow you to configure the server to deliver specific web application files based on the domain and directory structure of your server. Follow the steps below to create a new virtual host configuration for securely serving web applications.
Create a new Nginx virtual host configuration file in the sites available directory.
Add the following code to define the virtual host settings.
Save and close the file.
The above configuration ensures that Nginx listens for requests to the app.example.com domain and serves the content from the /var/www/app.example.com web root directory.
Link the virtual host configuration to the /etc/nginx/sites-enabled directory to activate in on the server.
Set up a new directory at /var/www/app.example.com to store your web application’s files
Create an HTML file (e.g., index.html) in the web root directory.
Add the following HTML content to the file.
Save and close the file.
The above HTML application displays a Greetings from Vultr message when accessed in a web browser.
Run the following command to check for any configuration errors.
Your output should be similar to the one below:
Restart the nginx service to apply the new virtual host configuration.
Access your domain defined in the virtual host using curl to confirm that the Nginx virtual host is working correctly.
If configured correctly, the command returns the following response:
SSL certificates protect data by encrypting communication between a user's browser and the Nginx web server over the HTTPS protocol. Since Nginx listens on the unencrypted HTTP port 80 by default, you can enhance security by generating a trusted SSL certificate with Let's Encrypt using Certbot. Follow the steps below to secure your Nginx server with HTTPS support.
Install the Certbot Let's Encrypt client using Snap.
VIew the installed Certbot version.
Your output should be similar to the one below:
Allow HTTP connections on port 80 for Certbot's ACME verification.
Generate an SSL certificate for your domain. Replace app.example.com with your actual domain name configured in the Nginx virtual host file.
Your output should be similar to the one below:
Uncomplicated Firewall (UFW) is installed and enabled by default on Ubuntu 25.04. Use the following steps to configure the UFW firewall and allow secure connections to your Nginx web server.
Allow HTTPS traffic on port 443.
View the UFW status and verify that the updated firewall rules are active.
Your output should be similar to the one below:
You have installed Nginx on your Ubuntu 25.04 server and configured it to securely serve applications over HTTPS using a trusted Let's Encrypt SSL certificate. Nginx supports multiple virtual host configurations and can be integrated with other services such as MySQL and PHP to deploy dynamic web applications. For additional configuration options, visit the official Nginx documentation.
0 Comments
Be the first to comment and share your perspective with the community.