
Nginx is an open-source web server application that enables the delivery of static and dynamic web applications or services. Install Nginx Web Server on Ubuntu to function as a web server, load balancer, reverse proxy, or HTTP cache.
This article provides a step-by-step process on how to install Nginx on Ubuntu 24.04 and set up sample web applications to run efficiently on your server.
Before you begin:
app.example.com.The latest Nginx package is available in the default APT repositories on Ubuntu 24.04. Follow the steps below to update the server packages and install the Nginx web server application.
Update the server package index.
Install Nginx.
View the installed Nginx version on your server.
Your output should be similar to the one below:
Nginx uses the nginx systemd service profile to control the web server run time, and processes on your server. Follow the steps below to enable the Nginx system service and manage the web server processes on your server.
Enable the Nginx web server to start automatically at boot time.
Output:
Start the Nginx service.
Stop the Nginx service.
Restart the Nginx service.
View the Nginx service status and verify that it's running.
Output:
Based on the above output value Active: active (running), Nginx is active and running on your server. If the service activity status includes Active: active (failed), stop any processes running on the HTTP port 80 and restart the nginx service.
Nginx virtual hosts include special configurations that enable the web server to deliver web application files from a specific directory using a specific domain on your server. In the following steps, create a new sample Nginx virtual host configuration to securely deliver web application files on your server.
Create a new Nginx virtual host configuration in the /etc/nginx/sites-available directory. For example, app.example.com.conf.
Add the following configurations to the file.
Save and close the file.
The above Nginx virtual host configuration listens for incoming connections using your app.example.com domain and serves your web application files from the /var/www/app.example.com web root directory on your server.
Test the Nginx configuration for errors.
Output:
Link the configuration to the /etc/nginx/sites-enabled directory to activate the virtual host on your server.
Create a new web root directory /var/www/app.example.com to store your web application files.
Create a new HTML application file within the directory. For example, index.html.
Add the following HTML contents to the file.
Save and close the file.
The above HTML application displays a Greetings from Vultr heading when accessed in a web browser.
Restart Nginx to apply the new virtual host configurations on your server.
Access your domain to verify that Nginx correctly delivers the virtual host web application files on your server. For example, use the Curl utility to test access to your domain.
Output:
SSL certificates enable encrypted communications between a user's browser and the Nginx web server using HTTPS. By default, Nginx listens for incoming connections on the insecure HTTP port 80 . Follow the steps below to generate trusted Let's Encrypt SSL certificates and secure the Nginx web server to enable encrypted HTTPS connection requests.
Install the Certbot Let's Encrypt client package using Snap.
View the installed Certbot version on your server.
Output:
Generate a new SSL certificate for your domain. Replace app.example.com with the actual domain in your Nginx virtual host configurations.
Uncomplicated Firewall (UFW) is available and active on Ubuntu 24.04 by default. In the following steps, configure the firewall with new connection rules to enable the Nginx web server to listen for incoming HTTP and HTTPS connections on your server.
Allow network connections on the HTTP port 80.
Allow connections on the HTTPS port 443.
View the UFW table and verify that the new connection rules are active.
Output:
You have installed Nginx on your Ubuntu 24.04 server and configured the web server to deliver web applications on your server. Nginx supports multiple virtual host configurations you can use to securely deliver web applications on your server. In addition, you can integrate the Nginx web server with other applications such as MySQL and PHP to deliver dynamic web applications on your server. For more information and configuration options, visit the official Nginx documentation.
0 Comments
Be the first to comment and share your perspective with the community.