To Install & Configure Nginx in Ubuntu 20.04, do the following
Note: Do the following steps only on a fresh server.
First, connect to the server using SSH root and update the server using the following command
sudo apt update -y
Now, Install Nginx using the following command
sudo apt install nginx -y
To check if Nginx is installed and enabled or not run the following commands
sudo systemctl status nginx
sudo systemctl is-enabled nginx
sudo apt install mysql-server -y
sudo mysql_secure_installation
sudo apt install php-fpm php-mysql -y
php --version
cd /var/www/
sudo mkdir domain_here
sudo nano /etc/nginx/sites-available/your_domain
server {
listen 80;
server_name your_domain www.your_domain;
root /var/www/your_domain;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
After that, unlink the default configuration file from the /sites-enabled/ directory:
sudo unlink /etc/nginx/sites-enabled/default
Now after these changes test the Nginx configurations by running the following command
sudo nginx -t
Now reload the Nginx configurations
sudo systemctl reload nginx
sudo systemctl restart nginx
That's it. Now you can create a test index.html file in /var/www/your_domain and open your domain in the browser to check it.
Do the above steps for setting up the second site.
Click Here for How to Install SSL on Nginx