Labels

Sunday, 8 February 2026

VF2L: Nginx

 Intro

Previously I have found that Docker works well on VF2L even though the server is not very powerful.  VF2L doesn't include Docker-Compose and it was educational for me to use command line tools.  There are limited pre-packaged images available for risc-v, but this isn't an issue as Alpine, Debian or Ubuntu can be used as a basis for installing software packages.

VF2L is convenient to use as a testing ground and I decided to try out nginx here even though I could use Docker on RPI or Windows where more docker capabilities are available (compose, desktop, OMV etc).

Proxy Servers

I don't have a good understanding of Proxy Servers.  Originally they were used so that a number of local clients could share an Internet IP address, more recently this has been replace by NAT (Network Address Translation) but proxy servers are still used by some to cache pages, filter available sites and for authentication.  This type of proxy is known as a forward proxy server. In contrast reverse proxy servers accept requests from the Internet and pass them to appropriate web / application servers for processing.  They protect internal servers from malicious users and provide SSL certificates and load balancing.  The title "proxy server" is used for either forward or reverse proxies, which can be confusing.


Nginx

Nginx is the leading proxy server used currently.  It provides a web server, reverse proxy, load balancing and caching. I noticed that it has an official Docker riscv64 image and decided to try it out on VF2L.
It was as simple as typing a docker run command to download the software and spin up a container.  I can then immediately access the nginx placeholder home page.  It only took a minute!

The nginx container runs on a stripped down debian image (126MB) and I needed to install "nano" so that I could create my own test home page in /usr/share/nginx/html/index.html.

After a little experimentation I configured a more useful container.  This has two volumes "html" for  webpages and "conf.d" for the nginx configuration file.  As these volumes are provided from VF2L I can conveniently edit the files on them outside the container then reload nginx in the container to update the configuration.
I also prefer to alpine linux (52MB) as a base over Debian for Docker servers.
As VF2L is a test server I allocated port 80 to be available for the web server. 

Nginx web server configuration

I started by creating an nginx web server.  This is very simple.  The default.conf file simply says that the server should listen on port 80 and the home page is to be found at /usr/share/nginx/html.
In my browser I enter the VF2L ip address and the container returns the ...nginx/html/index.html webpage from the server.

I added a couple of extra locations.  This provides the ability to setup separate web page mappings.

The URI http://192.168.0.25/second.html maps to ...nginx/html/second.html.
http://192.168.0.25/third/ maps to ...nginx/html/third/index.html.
I found it a little confusing that nginx adds in the location (e.g. /third/ ) to URI but this is useful.

nginx proxy server

Setting up a proxy server is just as easy.  I added a location /pi/ in my server configuration and specified using the proxy_pass argument that requests should be directed to my application server (192.168.0.41).
I also had to add a folder ..../pi/ on my application server containing the web page.
Now the request http://192.168.0.25/proxy/ returns the web page ...html/pi/index.html

nginx is also kind enough to allow you to setup multiple web servers in a single instance. I setup a second VF2L server on port 8080.

A request http://192.168.0.25/proxy/  is directed to "myproxied" and the page /usr/share/nginx/html/proxy/index.html is returned.


External Access


Of course the main purpose of a reverse proxy is to route requests coming from outside the local network.  As a test I setup my router to forward port 8080 to VF2L.  
Now I can enter my external ip address and add "/pi/".  My router sends the request to VF2L which looks at "/pi/" and forwards it to //PI41 which returns the web page html/pi/index.html.


Outro

This experimentation with nginx gives me some basic practical understanding of reverse proxies.  They are particularly useful for docker containers as there may be many http(s) ports in use on different containers and nginx can forward requests to the appropriate destination for processing.
There is a load more functionality which I can look at in nginx (SSL in particular) and I haven't created anything of long-term usefulness.  This sets me up well to use nginx with other docker applications, in the first instance this could be an opencloud or nextcloud server.

No comments:

Post a Comment