# Self hosting guide
In this guide I tell you how to install NGINX on your Linux based machine and how to serve the entire website all locally on your own network using hardware you control (Or you can make ...

In this guide I tell you how to install NGINX on your Linux based machine and how to serve the entire website all locally on your own network using hardware you control (Or you can make it public but you need a domain and a SSL cert)

# Requirements

- Basic Linux knowledge.
- A Linux server (Ex. Old laptop or even a RasberryPi
  ) or Linux VM/LXC (Ex. Proxmox
  , VMware
  , or basically any Linux VPS like Hetzner
  , DigitalOcean
  , AWS
  ).
  - Preferably running a Debian based distribution (If your using another one some commands may be different but you should be able to figure it out)

# Guide

## Install NGINX

> (Recommended) Debian and Ubuntu

> Update the Debian repository information:

>     sudo apt-get update

> Install the NGINX Open Source package:

>     sudo apt-get install nginx

> Verify the installation:

>     sudo nginx -v

> Alpine Linux

> Install the prerequisites:

>     sudo apk add openssl curl ca-certificates

> To set up the apk repository for stable NGINX packages, run the command:

>     printf "%s%s%s\n" \
>     "http://nginx.org/packages/alpine/v" \
>     `egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release` \
>     "/main" \
>     | sudo tee -a /etc/apk/repositories

> Import an official NGINX signing key so apk could verify the packages authenticity. Fetch the key:

>     curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub

> Verify that the downloaded file contains the proper key:

>     openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout

> The output should contain the following modulus:

>     Public-Key: (2048 bit)
>     Modulus:
>         00:fe:14:f6:0a:1a:b8:86:19:fe:cd:ab:02:9f:58:
>         2f:37:70:15:74:d6:06:9b:81:55:90:99:96:cc:70:
>         5c:de:5b:e8:4c:b2:0c:47:5b:a8:a2:98:3d:11:b1:
>         f6:7d:a0:46:df:24:23:c6:d0:24:52:67:ba:69:ab:
>         9a:4a:6a:66:2c:db:e1:09:f1:0d:b2:b0:e1:47:1f:
>         0a:46:ac:0d:82:f3:3c:8d:02:ce:08:43:19:d9:64:
>         86:c4:4e:07:12:c0:5b:43:ba:7d:17:8a:a3:f0:3d:
>         98:32:b9:75:66:f4:f0:1b:2d:94:5b:7c:1c:e6:f3:
>         04:7f:dd:25:b2:82:a6:41:04:b7:50:93:94:c4:7c:
>         34:7e:12:7c:bf:33:54:55:47:8c:42:94:40:8e:34:
>         5f:54:04:1d:9e:8c:57:48:d4:b0:f8:e4:03:db:3f:
>         68:6c:37:fa:62:14:1c:94:d6:de:f2:2b:68:29:17:
>         24:6d:f7:b5:b3:18:79:fd:31:5e:7f:4c:be:c0:99:
>         13:cc:e2:97:2b:dc:96:9c:9a:d0:a7:c5:77:82:67:
>         c9:cb:a9:e7:68:4a:e1:c5:ba:1c:32:0e:79:40:6e:
>         ef:08:d7:a3:b9:5d:1a:df:ce:1a:c7:44:91:4c:d4:
>         99:c8:88:69:b3:66:2e:b3:06:f1:f4:22:d7:f2:5f:
>         ab:6d
>     Exponent: 65537 (0x10001)

> Move the key to `apk` trusted keys storage:

>     sudo mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/

> To install NGINX, run the command:

>     sudo apk add nginx

> RHEL, CentOS, Oracle Linux, AlmaLinux, Rocky Linux

> Install the EPEL repository:

>     sudo yum install epel-release

> Update the repository:

>     sudo yum update

> Install NGINX Open Source:

>     sudo yum install nginx

> Verify the installation:

>     sudo nginx -v

> SUSE

> Install the prerequisites:

>     sudo zypper install curl ca-certificates gpg2

> To set up the `zypper` repository for stable NGINX packages, run the following command:

>     sudo zypper addrepo --gpgcheck --type yum --refresh --check \
>        'http://nginx.org/packages/sles/$releasever_major' nginx-stable

> Import an official NGINX signing key so `zypper/rpm` could verify the packages authenticity. Fetch the key:

>     curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key

> Verify that the downloaded file contains the proper key:

>     gpg --with-fingerprint /tmp/nginx_signing.key

> The output should contain the full fingerprints: `8540 A6F1 8833 A80E 9C16 53A4 2FD2 1310 B49F 6B46`, `573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62`, `9E9B E90E ACBC DE69 FE9B 204C BCDC D8A3 8D88 A2B3` as follows:

>     pub   rsa4096 2024-05-29 [SC]
>           8540A6F18833A80E9C1653A42FD21310B49F6B46
>     uid                      nginx signing key <signing-key-2@nginx.com>

>     pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
>           573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
>     uid                      nginx signing key <signing-key@nginx.com>

>     pub   rsa4096 2024-05-29 [SC]
>           9E9BE90EACBCDE69FE9B204CBCDCD8A38D88A2B3
>     uid                      nginx signing key <signing-key-3@nginx.com>

> If the fingerprint is different, remove the file.

> Import the key to the rpm database:

>     sudo rpmkeys --import /tmp/nginx_signing.key

> To install NGINX, run the command:

>     sudo zypper install nginx

> Amazon Linux

> Install the prerequisites:

>     sudo yum install yum-utils

> To set up the `yum` repository for Amazon Linux 2, create the file named `/etc/yum.repos.d/nginx.repo` with the following contents:

>     [nginx-stable]
>     name=nginx stable repo
>     baseurl=http://nginx.org/packages/amzn2/$releasever/$basearch/
>     gpgcheck=1
>     enabled=1
>     gpgkey=https://nginx.org/keys/nginx_signing.key
>     module_hotfixes=true

>     [nginx-mainline]
>     name=nginx mainline repo
>     baseurl=http://nginx.org/packages/mainline/amzn2/$releasever/$basearch/
>     gpgcheck=1
>     enabled=0
>     gpgkey=https://nginx.org/keys/nginx_signing.key
>     module_hotfixes=true

> To set up the `yum` repository for Amazon Linux 2023, create the file named `/etc/yum.repos.d/nginx.repo` with the following contents:

>     [nginx-stable]
>     name=nginx stable repo
>     baseurl=http://nginx.org/packages/amzn/2023/$basearch/
>     gpgcheck=1
>     enabled=1
>     gpgkey=https://nginx.org/keys/nginx_signing.key
>     module_hotfixes=true

>     [nginx-mainline]
>     name=nginx mainline repo
>     baseurl=http://nginx.org/packages/mainline/amzn/2023/$basearch/
>     gpgcheck=1
>     enabled=0
>     gpgkey=https://nginx.org/keys/nginx_signing.key
>     module_hotfixes=true

> Install nginx:

>     sudo yum install nginx

> When prompted to accept the GPG key, verify that the fingerprint matches: `8540 A6F1 8833 A80E 9C16 53A4 2FD2 1310 B49F 6B46`, `573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62`, `9E9B E90E ACBC DE69 FE9B 204C BCDC D8A3 8D88 A2B3`, and if so, accept it.

> Arch Linux (Not Recommended)

> If your using Arch Linux
> on your server follow this guide
> the Arch Wiki
> has some of the best most in-depth guides I’ve seen. (Arch is amazing for a Linux desktop but not great in a server environment due to it being a rolling release distribution you will have to deal with the downtime from managing package/kernel updates daily. I would recommend Alpine Linux
> over Arch because its a release based distribution)

## Hosting

> Faq

> I wrote this part assuming your using a Debian based distribution. If your using another you may need to change some commands (depending on your service manager `service` may be `systemctl` for example if your using `systemd`), install `git`, or replace `/var/www` with whatever folder you want.

Clone the repository containing the site backup inside of `/var/www`.

    cd /var/www
    git clone https://git.slavserver.com/DooSkagg/SlavinskyCookbook-Backup.git .

Find your nginx default config by running this command:

    find / 2>/dev/null -wholename '*/nginx/sites-enabled/default'

Open it using `vim` or `nano` (or any other text editor) delete all lines inside of the default config and paste the following in:

    server {
        listen 80;
        server_name example.com;
        root /var/www;
        index index.html;
        error_page 404 /404.html;

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

change the `example.com` in line 3 to either the domain your going to host it on or the local IP of your server.

Restart NGINX (May be different command depending on your Linux distro)

    service nginx restart

Access your site at `http://[IP_OF_SERVER]:80` For HTTPS support this guide
should help you

> Tip

> You can also skip all of this and download
> the site files as a `.zip` and upload them to Cloudflare Pages
> for free hosting (I’m personally not a fan of this because I like running everything on my own hardware).