
Nginx is an open-source, high-performance webserver that also works as a reverse proxy and a load balancer for backend applications. Nginx integrates with modern server-side scripting languages like Python, Golang, and PHP to run dynamic data-driven web applications.
This article explains how to install Nginx on Debian 12, set up virtual hosts, and secure the webserver with Let's Encrypt.
Before you begin:
app.example.com.Nginx is available in the default package repositories on Debian 12. Follow the steps below to update the server package index and install Nginx using the APT package manager.
Update the server's package information index.
Install Nginx.
Allow HTTP port 80 through the firewall.
Allow HTTPS port 443 through the firewall.
Reload UFW to apply the firewall changes.
Visit your server's public IP address using a web browser such as Chrome to test access to the default Nginx welcome page.
Nginx uses the nginx systemd service profile to manage the webserver application processes. To manage the service using systemctl, follow the steps below.
Enable the Nginx service to start at boot automatically.
Start the Nginx service.
View the Nginx service status and verify that it's running.
Output:
Stop the Nginx service.
Restart the Nginx service.
Nginx virtual host configurations enable the webserver to host multiple websites on a single server. A virtual host configuration consists of multiple directives that define the root directory, server name, error files, and index pages for a specific domain name. Follow the steps below to create a new Nginx virtual host.
Create a new Nginx virtual host configuration file. For example, app.example.com.conf.
Open the file using a text editor like nano.
Add the following contents to the file. Replace app.example.com with your actual domain.
Save and close the file.
The above Nginx configuration creates a new virtual host that listens for incoming connections for the app.example.com domain and delivers web application files from the /var/www/html/app.example.com directory.
Create the virtual host's web root directory.
Create a new index.html web application file in the directory.
Add the following contents to the file.
Save and close the file.
When you access the above HTML web application in a web browser, you will see a Greetings from Vultr message.
Grant the www-data webserver user and group ownership privileges to the /var/www/html/app.example.com directory.
Test the Nginx configuration for errors.
Output:
Restart the Nginx service to apply the changes.
Access your domain on a web browser and verify that your web application displays.
Nginx listens for incoming HTTP connections on port 80. To secure the Nginx virtual host through the HTTP port 443, you must install a trusted SSL certificate. Follow the steps below to install a Let's Encrypt SSL certificate.
Install the Certbot Let's Encrypt client tool and the Nginx plugin.
Generate a new SSL certificate for the virtual host. Replace app.example.com with your actual virtual host domain and hello@example.com with your active email address.
Ensure Certbot can renew the SSL certificate.
Restart Nginx to apply the configuration changes.
Visit your virtual host domain using HTTPS and verify that your web application displays.
You have installed Nginx on Debian 12, set up a new virtual host, and installed a Let's Encrypt Certificate. Nginx works as a webserver, a load balancer, or a reverse proxy. For more information, visit the Nginx documentation.
0 Comments
Be the first to comment and share your perspective with the community.