The BobSprite Raw Blog


Pixel Art, Programming and Video Games

(click here and go to index)

How to Write a Simple NGINX Directive File


NGINX text logo
NGINX is very nice except for its config files that are hard to write. If you just want to have your basic Nginx stuff done, then maybe the model that I have been using for years is what you need.

Features

This model expects that Let's Encrypt is the choice for the   HTTPS   protocol.

This model expects that the index page is   "/home.html".

This model expects that the error page is   "/404.html".

This model redirects   HTTP   protocol requests to   HTTPS   protocol.

This model redirects   "https://bobsprite.com"   to   "https://www.bobsprite.com".

This model redirects   "https://bobsprite.com/ANYTHING.html"   to   "https://www.bobsprite.com/ANYTHING".

Of course it serves files that have the   ".html"   extension for requests that don't have this extension.

It used to pass requests for "/analytics" to an internal NodeJs server but it is disabled now. So it responds with "[under construction]".

Editing the Model

You must replace "bobsprite" everywhere with your own domain.

You must replace "/home.html" using your index page address, in case it is different.

You must replace "/404.html"  using your error page address, in case it is different.

CertBot

I don't like CertBot messing my config files. So I *never* use this command:

sudo certbot --nginx

But I use this:

sudo certbot certonly --nginx

The Model

NGINX directive

The directive above is an image. You may access this directive text file here.

I hope it helps!

Disclaimer

I am not a server expert.