Configure NGINX on a VPS
Context
To practice using Linux, I created this script to simplify setting up an NGINX server on a VPS in order to host a website.
Step-by-step Script Breakdown
Install NGINX
Install the nginx
web server, essential for hosting a static website (~10 seconds).
Define Domain Name
Choose the domain name to be used for the website configuration (~1 second).
Set Web Directory Permissions
Grant permissions to the current user to manage the website content (~1 second).
Create Website Directory Structure
Create the /var/www/domainname/public
structure to host the website files (~2 seconds).
Add a Test Page
Add a index.html
test file to verify the site is up and running (~1 second).
Remove Default Configs
Delete NGINX’s default configuration files to avoid conflicts (~2 seconds).
Create a Custom NGINX Config
Write a custom server block for the domain name pointing to the right directory (~3 seconds).
Enable the Configuration
Create a symbolic link in sites-enabled
, then test and reload NGINX (~3 seconds).
Install Certbot
Install certbot
with NGINX support to generate an SSL certificate (~10 seconds).
Generate SSL Certificate
Run certbot
to automatically generate and apply a Let's Encrypt HTTPS certificate (~30 seconds).
Test Renewal
Show an informational message and run a test for automatic certificate renewal (~5 seconds).