Information
The instructions in this article apply only to the NGINX web server, not to the software that will be installed on it.
Requirements
- A server running Debian Linux
- A domain name
- DNS configured to point to the server’s IP address
suorsudoprivileges to execute commands as root
Preparation
Ensure the system is up to date before starting the installation.
ssh user@server
sudo apt update && sudo apt upgrade
NGINX
Installation
Install NGINX using the apt command.
sudo apt install nginx
Configuration
Information
In the code below, replace example with your domain name, without https:// or www unless explicitly required (e.g., example.com).
- Enable NGINX to start automatically with the server.
sudo systemctl enable --now nginx
- Copy the default site configuration.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
- Edit the configuration with
nano.
sudo nano /etc/nginx/sites-available/example.com
server {
server_name example.com www.example.com;
root /var/www/example.com/public/;
index index.html;
location / {
try_files $uri $uri/ =404;
}
listen 80;
listen [::]:80;
}
Tip
You can paste into the terminal using CTRL + SHIFT + V.
- Activate the configuration by creating a symbolic link.
sudo ln -s /etc/nginx/sites-available/example.com \
/etc/nginx/sites-enabled/example.com
- Test and reload NGINX.
sudo nginx -t
sudo systemctl reload nginx
CertBot
Installation
Install CertBot using apt.
sudo apt install certbot python3-certbot-nginx
Configuration
Generate and apply a valid SSL certificate with the following command.
sudo certbot --nginx
Follow the prompts, providing your email address and selecting the sites to secure.
Tip
If you want to test the configuration before fetching a certificate, use the --dry-run option.
sudo certbot --nginx --dry-run
Activating the website
- Create an
index.htmlfile and add some content, for example:
sudo mkdir -p /var/www/example.com/public
sudo nano /var/www/example.com/public/index.html
<html>
<body>
<h1>Hello world</h1>
</body>
</html>
- Assign ownership to the
www-datauser and group, and set proper permissions.
sudo chown www-data:www-data /var/www/example.com -R
sudo chmod -R g+rwX /var/www/example.com
- Open a browser and navigate to your website; you should now see the contents of the index.html file.