Oct 16, 2022

Manually Install and configure Nginx with Multipass

Found a great tutorial site at Ubuntu.

Let me follow the tutorial to setup a Nginx web server with multipass.

$ multipass launch --name nginxweb -c 2 -m 2G

$ multipass shell nginxweb

ubuntu@nginxweb:~$ sudo apt update
ubuntu@nginxweb:~$ sudo apt install nginx 

ubuntu@nginxweb:~$ cd /var/www
ubuntu@nginxweb:~$ sudo mkdir tutorial
ubuntu@nginxweb:~$ cd tutorial
ubuntu@nginxweb:~$ sudo "${EDITOR:-vi}" index.html

Insert the following content and save index.html:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello, Nginx!</title>
</head>
<body>
    <h1>Hello, Nginx!</h1>
    <p>We have just configured our Nginx web server on Ubuntu Server!</p>
</body>
</html>

Next, configure Nginx web to start a new web instance at port 81.

ubuntu@nginxweb:~$ cd /etc/nginx/sites-enabled
ubuntu@nginxweb:~$ sudo "${EDITOR:-vi}" tutorial

Again, insert the following content and save the tutorial file:

server {
       listen 81;
       listen [::]:81;

       server_name example.ubuntu.com;

       root /var/www/tutorial;
       index index.html;

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

Last, restart Nginx, and capture the IP address and make sure everything is working.

ubuntu@nginxweb:~$ sudo service nginx restart

ubuntu@nginxweb:~$ ip a 

Open the browser (at host) and point to http://<ip>:81/ and http://<ip>/

(All the works complete within 4 min at my laptop)


Link: