Alpine — Add a Web Server

How to add a Web Server to a regular Linux virtual machine. A minimal Alpine VM is a good base for services like Nginx as a web server. Alpine ensures minimal VM overhead.

Share
Alpine — Add a Web Server
Photo by Lee Roylland / Unsplash

This is a short post of adding a Nginx web server to an Alpine VM.

Install

doas apk update && doas apk add nginx

Add a user

doas adduser -D -g 'www' www

Create a directory for HTML -files

doas mkdir /www
doas chown -R www:www /var/lib/nginx
doas chown -R www:www /www

Configuring NginX to listen to port 80

doas nano /etc/nginx/nginx.conf

Start Nginx

After the installation, NginX is not running. To start NginX, use start.

doas rc-service nginx start

Adding the community repo

If you need things like the Qemu-Guest-Agent or sudo, you need to activate the community repo. Edit the file /etc/apk/repositories and remove the # in front of the …/community lines.

Change the IP

If you use DHCP reservations:

Your /etc/network/interfaces looks like this:

auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet dhcp

Show by cat /etc/network/interfaces

  • Go to the DHCP server
    • Add or change the IP for the VM
  • On the VM
    • restart the network

IPv4 static address configuration for Alpine Linux version 3.x.x

doas vi /etc/network/interfaces

Set a new single IP

auto eth0
iface eth0 inet static
        address 192.0.2.250/24
        gateway 192.0.2.1
        hostname ISOs-a733

Set dual or more IPs

iface eth0 inet static
        address 192.0.2.250/24
        gateway 192.0.2.1
        hostname ISOs-a733
 
iface eth0 inet static
        address 192.168.1.250/24

Set a new IPv6 address

iface eth0 inet6 static
        address ipv6-here/64
        gateway ipv6-gw-here
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

Configure the DNS Client

Setting the nameserver IP addresses

doas vi /etc/resolv.conf

Append the new IP(s)

nameserver 192.0.2.1

Restating network service

doas service networking restart