Skip to content

Nginx

Overview

NGINX is a high‑performance, highly scalable, highly available web server, reverse proxy server, and web accelerator ( combining the features of an HTTP load balancer, content cache, and more). NGINX has a modular, event‑driven, asynchronous, single-threaded architecture that scales well on generic server hardware and across multi-processor systems. NGINX uses all the underlying power of modern operating systems like Linux to optimize the usage of memory, CPU, and network, and extract the maximum performance out of a physical or virtual server.


In this tutorial we will be covering a simple example of how to create a Generic Application and use NGINX as a simple web server. We will be also showing how to deploy and access this web server.

Prerequisite:

  1. Complete the Getting Started Guide.

Source Code

The source code for this application is available at GitHub.

In this tutorial we will learn the following features

  • How to use a host network port.
  • How to mount a volume to serve a static HTML file.

Create a docker type application

kelvin app create --app-type docker kelvin-nginx-tutorial
cd kelvin-nginx-tutorial

Start Kelvin Studio

We will use Kelvin Studio to modify the app.yaml. To start Kelvin studio use the following command:

nginx-app-yaml-studio.png

kelvin studio start --input-file app.yaml

Once Kelvin Studio opens, you will see the following:

App Yaml

Configure the new generic docker application

In this example, we will use the latest NGINX version. Start by defining the Dockerfile and its contents:

FROM nginx:latest

Next, select the System Requirements tab, then on the left menu, click in Port Mappings and add a new port. Fill with the following values:

  • Port name = http-port
  • Port type = host
  • Port = 80

Port Mapping

We now need to create a volume which will serve a simple static HTML page. Click in Volumes in the left menu and add a new item. Fill with the following information:

  • Volume name = static-page
  • Volume target = /usr/share/nginx/html/index.html
  • Volume type = text
  • Base64 = true

Set the Data with the following information:

PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KCTxtZXRhIGNoYXJzZXQ9InV0Zi04Ij4KCTxtZXRhIGh0dHAtZXF1aXY9IlgtVUEtQ29tcGF0aWJsZSIgY29udGVudD0iSUU9ZWRnZSI+Cgk8dGl0bGU+S0lDUyBwbGF0Zm9ybTwvdGl0bGU+Cgk8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9IiI+Cgk8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJCWJvZHkgewoJCQltYXJnaW46IDIwcHg7Cgk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LjYwNGwtOC45MzggOC4yNVYxMC43MmgtMS4xNDVWMjkuMjhoMS4xNDV2LTkuNjI1bDkuMzk2IDkuNTF6Ij48L3BhdGg+CgkJCQkJCTxjaXJjbGUgZmlsbD0iY3VycmVudGNvbG9yIiBjeD0iMTEuNzUiIGN5PSIxMS4wNjMiIHI9IjEiPjwvY2lyY2xlPgoJCQkJCTwvZz4KCQkJCTwvc3ltYm9sPgoJCQk8L3VzZT4KCQk8L3N2Zz4KCTwvZGl2PgoJPGRpdiBzdHlsZT0idGV4dC1hbGlnbjogY2VudGVyOyBjb2xvcjogIzM2NjU2ZCI+CgkJPGgyPgoJCQlXZWxjb21lIHRvIHRoZSBLSUNTIHBsYXRmb3JtCgkJPC9oMj4KCTwvZGl2PgoJPGRpdiBzdHlsZT0idGV4dC1hbGlnbjogbGVmdDsgbWF4LXdpZHRoOiAxMjgwcHg7IG1hcmdpbjogMCBhdXRvOyI+CgkJVGhlIEtJQ1MgUGxhdGZvcm0gZW5hYmxlcyBhcHBsaWNhdGlvbiBjcmVhdGlvbiBhbmQgbWFuYWdlbWVudCwgYWxvbmcgd2l0aCBkZXZpY2UgbWFuYWdlbWVudCBhbmQgb3JjaGVzdHJhdGlvbiwgdG8gYXVnbWVudCBsZWdhY3kgY29udHJvbCBzeXN0ZW1zIHdpdGggbW9kZXJuIHJlYWwtdGltZSBvcHRpbWl6YXRpb24gYW5kIGNvbnRyb2wuIEtlbHZpbiBhcHBzIGNhbiBhbHNvIHN0cmVhbSB2YWx1YWJsZSBtZXRyaWNzIGFuZCBhZ2dyZWdhdGVzIGJhY2sgdG8gdGhlIHRpbWUtc2VyaWVzIERhdGEgQmFzZSBmb3IgZnVydGhlciBhbmFseXRpY3MgYW5kIGluc2lnaHQuCgk8L2Rpdj4KPC9ib2R5Pgo8L2h0bWw+Cgo=

Volume

The final step is to save this configuration. Click on the Save button in the top right. You can now exit the Kelvin Studio. To confirm our configuration changes, check the app.yaml file. It shall match the content below:

app:
docker:
  build:
  context: .
  dockerfile: Dockerfile
  image: 'nginx:latest'
type: docker
info:
description: kelvin-nginx-tutorial
name: kelvin-nginx-tutorial
title: kelvin-nginx-tutorial
version: 1.0.0
spec_version: 1.0.0
system:
ports:
  - type: host
  name: http-port
  host:
    port: 80
volumes:
  - name: static-page
  target: /usr/share/nginx/html/index.html
  type: text
  text:
    base64: true
    encoding: utf-8
    data: >-
    PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KCTxtZXRhIGNoYXJzZXQ9InV0Zi04Ij4KCTxtZXRhIGh0dHAtZXF1aXY9IlgtVUEtQ29tcGF0aWJsZSIgY29udGVudD0iSUU9ZWRnZSI+Cgk8dGl0bGU+S0lDUyBwbGF0Zm9ybTwvdGl0bGU+Cgk8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9IiI+Cgk8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJCWJvZHkgewoJCQltYXJnaW46IDIwcHg7CgkJCXBhZGRpbmc6IDBweDsKCQkJZm9udC1mYW1pbHk6IEhlbHZldGljYSwgQXJpYWw7CgkJCWJhY2tncm91bmQtY29sb3I6ICNEREQ7CgkJCWNvbG9yOiAjNDQ0OwoJCQlmb250LXNpemU6IDEuNWVtOwoJCQlsaW5lLWhlaWdodDogMS41OwoJCX0KCTwvc3R5bGU+CjwvaGVhZD4KPGJvZHk+Cgk8ZGl2IHN0eWxlPSJ0ZXh0LWFsaWduOiBjZW50ZXI7Ij4KCQk8c3ZnPgoJCQk8dXNlIF9uZ2NvbnRlbnQtcWJmLWM4Mz0iIiB4bGluazpocmVmPSIjcGstbG9nby1rZWx2aW4iPgoJCQkJPHN5bWJvbCBpZD0icGstbG9nby1rZWx2aW4iIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDQwIDQwIj4KCQkJCQk8ZyBjb2xvcj0iIzM2NjU2ZCI+CgkJCQkJCTxwYXRoIGZpbGw9ImN1cnJlbnRjb2xvci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BjcmVhdGlvbiBhbmQgbWFuYWdlbWVudCwgYWxvbmcgd2l0aCBkZXZpY2UgbWFuYWdlbWVudCBhbmQgb3JjaGVzdHJhdGlvbiwgdG8gYXVnbWVudCBsZWdhY3kgY29udHJvbCBzeXN0ZW1zIHdpdGggbW9kZXJuIHJlYWwtdGltZSBvcHRpbWl6YXRpb24gYW5kIGNvbnRyb2wuIEtlbHZpbiBhcHBzIGNhbiBhbHNvIHN0cmVhbSB2YWx1YWJsZSBtZXRyaWNzIGFuZCBhZ2dyZWdhdGVzIGJhY2sgdG8gdGhlIHRpbWUtc2VyaWVzIERhdGEgQmFzZSBmb3IgZnVydGhlciBhbmFseXRpY3MgYW5kIGluc2lnaHQuCgk8L2Rpdj4KPC9ib2R5Pgo8L2h0bWw+Cgo=
privileged: false

Build and upload the new generic docker image

kelvin app build
kelvin appregistry upload

Deploy to a Node

For this example we will deploy the application to a Node via the Kelvin SDK. This can also be done in Control Center. Update the command below with the Node name (<node-name>) you would like the application deployed to.

kelvin workload deploy --app-name kelvin-nginx-tutorial --app-version 1.0.0 --app-config app.yaml --workload-name kelvin-nginx-tutorial --node-name <node-name>

Check and validate the workload

Open Control Center and go to the Node, where the app was deployed. Open the workload profile page, by clicking on the Workload name. You will see that the workload is running and, in the Network tab, you will have information about the Node IP address.

Workload details

!!! warning "Documentation on how to access the Node IP address is out of the scope of this tutorial. If you are running the Node in a VM inside your computer you shouldn't have any problem."

Open that IP address in your browser. If you see the following page, it means everything is working properly:

Result

Logo

Kelvin Documentation AI Support

Hi. My name is KevDocBot. How can I help you?