
Nginx is an open-source web server that delivers static and dynamic web applications or services. It functions as a web server, load balancer, reverse proxy, or HTTP cache, integrating with existing applications or delivering web services via your server's IP or domain.
This article outlines the steps to install Nginx on Ubuntu 20.04 and configure sample web applications for optimal performance.
Before you begin:
Have an Ubuntu 20.04 server.
Set up a new A record for your domain that points to the server IP address.
Access the server using SSH as a non-root user with sudo privileges.
The latest Nginx package is available in the default APT repositories for Ubuntu 20.04. Follow the steps below to update your server packages and install Nginx.
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 manage the web server's runtime and processes. Follow the steps below to enable the Nginx service and control 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 output value Active: active (running), Nginx is running on your server. If the status shows Active: active (failed), stop any processes using HTTP port 80 and restart the nginx service.
Nginx virtual hosts include configurations that allow the web server to serve web application files from a specific directory using a domain on your server. Follow the steps below to create a new sample Nginx virtual host configuration for secure file delivery.
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 provide encrypted communication between a user's browser and the Nginx web server via HTTPS. Nginx listens for incoming connections on the insecure HTTP port 80 by default. Follow the steps below to generate trusted Let's Encrypt SSL certificates and secure Nginx to enable encrypted HTTPS connections.
Install the Certbot Let's Encrypt client package using Snap.
View the installed Certbot version on your server.
Output:
Allow network connections on the HTTP port 80 for Certbot ACME verification.
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 enabled by default on Ubuntu 20.04. Follow the steps below to configure the firewall with rules that allow Nginx to listen for incoming HTTP and HTTPS connections on your server.
Allow connections on the HTTPS port 443.
View the UFW table and verify that the new connection rules are active.
Output:
You have successfully installed Nginx on your Ubuntu 20.04 server and set it up to serve web applications. Nginx supports various virtual host configurations for secure delivery of applications. It can also integrate with other technologies like MySQL and PHP to power dynamic web applications.
0 Comments
Be the first to comment and share your perspective with the community.