How To Configure the Nginx Web Server on an Ubuntu or Debian VPS

Опубликовано: 02 Ноябрь 2024
на канале: MivoCloud
213
54

Although earlier we considered how to install a web server on our server, but we missed an important point with setting up a virtual host. Today we will fix this and show you how to set up a virtual host on an Nginx web server

Commands Used
apt update && apt upgrade -y
apt install nginx -y
sudo mkdir -p /var/www/your_domain/html
sudo chown -R $USER:$USER /var/www/your_domain/html
sudo chmod -R 755 /var/www/your_domain
nano /var/www/your_domain/html/index.html
sudo nano /etc/nginx/sites-available/your_domain

server {
listen 80;
listen [::]:80;

root /var/www/your_domain/html;
index index.html index.htm index.nginx-debian.html;

server_name your_domain www.your_domain;

location / {
try_files $uri $uri/ =404;
}
}

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Useful Links
VPS/VDS - https://www.mivocloud.com/