Skip to content

NGINX

This example assumes using Alma Linux 8 as the server operating system, first, install NGINX:

Installation

dnf install nginx -y

Start and enable the service:

systemctl enable nginx.service --now

If not already installed, install firewalld:

dnf install firewalld -y

If not already running, enable and start the service:

systemctl enable firewalld.service --now

Open up the firewall to allow both HTTP and HTTPS traffic:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Review the changes to the firewall:

firewall-cmd --list-all

Static Site

Update the main NGINX configuration file to include include /etc/nginx/sites-enabled/*.conf;, for example:

/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;
}

Create two directories for adding sites:

mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled /var/www/exampleforyou.net

Then add a basic HTTP configuration for

/etc/nginx/sites-available/exampleforyou.conf
server {
    listen 80;
    server_name exampleforyou.net www.exampleforyou.net;

    access_log /var/log/nginx/www.exampleforyou.net.access_log main;
    error_log /var/log/nginx/www.exampleforyou.net.error_log debug;

    location / {
      root /var/www/exampleforyou.net;  
      index index.html;    
    }
}

Create a soft link to activate the site:

ln -s /etc/nginx/sites-available/exampleforyou.conf /etc/nginx/sites-enabled/exampleforyou.conf

Validate the configuration:

nginx -t

Restart the NGINX service:

systemctl restart nginx.service