Linux Notes: Nginx (moving from Apache httpd to Nginx)
- The information presented here is intended for educational use by qualified computer technologists.
- The information presented here is provided free of charge, as-is, with no warranty of any kind.
Edit: 2026-09-19
back to: my
Linux Notes (index)
Overview
- Nginx first appeared in 2004, and was written to get around the 10k connection limit found in Apache
HTTPd at that time.
- Nginx is much faster than Apache HTTPd, and the Nginx config file is much smaller.
- enabling CGI (Common Gateway Interface) is not so easy, and the recipe
appears to be different on every platform including different Linux distros (and sometimes different versions of the same distro)
- Apache HTTPd first appeared in 1995 and was based upon NCSA
HTTPd which first appeared in 1993.
- It has been continuously updated since then and new versions continue to appear on all platforms including Linux.
- Apache solved the 10k connection limit in 2012 with the release of Apache-2.4
- Enabling CGI (Common Gateway Interface) is very easy to do via module mod_cgi
Moving from Apache httpd to Ngnix (2026-09-16)
Step-1 (installing Nginx on AlmaLinux-9.8)
Step-2 (enabling CGI on AlmaLinux-9.8)
Step-3 (enabled autoindex on AlmaLinux-9.8)
- for directories without a default html index, we want to display a directory listing
- not unremarkable here, it is almost identical to what you would do in Apache
Step-4 (enabled fancyindex on AlmaLinux-9.8)
Step-5 (enabled password protection of one folder)
My current conf (2026-09-17)
# ============================================================================
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# ============================================================================
# 1) 2026-09-14: changes to get CGI working with fastcgi / fcgi.
# 2) 2026-09-14: enabled autoindex
# 3) 2026-09-15: switched over to fancyindex (an optional package that might
# not be on your system). On AlmaLinux-9 you need to do this first:
# sudo dnf install nginx-mod-fancyindex.x86_64
# 4) 2026-09-16: enabled password protection on one folder
# ============================================================================
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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;
access_log /var/log/nginx/access.log main buffer=8k flush=1m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
# listen [::]:80;
server_name neilrieck.net;
# root /usr/share/nginx/html;
root /var/www/html; # my Apache files live here
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#error_page 404 /404.html;
#location = /404.html {
#}
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#}
location ~ ^/mira/ {
auth_basic "Restricted Access";
# auth_basic_user_file /etc/nginx/.htpasswd;
auth_basic_user_file /etc/nginx/passwd-folder-mira;
# "autoindex" is built into nginx
# autoindex on;
# autoindex_exact_size off;
# ------------------------------------
# "fancyindex" is not built into nginx
fancyindex on;
fancyindex_default_sort name;
fancyindex_directories_first on;
fancyindex_case_sensitive off;
fancyindex_exact_size off;
fancyindex_time_format "%Y-%m-%d %H:%M";
fancyindex_css_href "/css/nsr-folder-default.css";
try_files $uri $uri/ =404;
}
location / {
# "autoindex" is built into nginx
# autoindex on;
# autoindex_exact_size off;
# ------------------------------------
# "fancyindex" is not built into nginx
fancyindex on;
fancyindex_default_sort name;
fancyindex_directories_first on;
fancyindex_case_sensitive off;
fancyindex_exact_size off;
fancyindex_time_format "%Y-%m-%d %H:%M";
fancyindex_css_href "/css/nsr-folder-default.css";
}
location /cgi-bin/ {
# Disable gzip so script outputs stream properly if needed
gzip off;
# The root directory where your 'cgi-bin' folder lives
# e.g., if files are in /var/www/html/cgi-bin/, set root to /var/www/html
root /var/www/html; # my Apache files live here
# Pass requests to the fcgiwrap Unix socket
# fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_pass unix:/run/fcgiwrap/fcgiwrap-nginx.sock;
# Include standard Nginx FastCGI parameters
include fastcgi_params;
# Map the exact script filename to be executed
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2;
# listen [::]:443 ssl http2;
server_name neilrieck.net;
# root /usr/share/nginx/html;
root /var/www/html; # my Apache files live here
# ssl_certificate "/etc/pki/nginx/server.crt";
ssl_certificate "/etc/pki/tls/certs/neilrieck.net-20251022.cer";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
ssl_certificate_key "/etc/pki/tls/private/neilrieck.net-20251022.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#error_page 404 /404.html;
# location = /40x.html {
#}
#error_page 500 502 503 504 /50x.html;
# location = /50x.html {
#}
#
# password protected folder
# 1) this special folder is password protected so needs to be encountered first
# 2) this folder needs to have its own autoindex directives, or fancyindex directives.
# A common location entry (like the one 17-lines below) will not work here.
#
location ~ ^/mira/ {
auth_basic "Restricted Access";
# auth_basic_user_file /etc/nginx/.htpasswd;
auth_basic_user_file /etc/nginx/passwd-folder-mira;
# "autoindex" is built into nginx
# autoindex on;
# autoindex_exact_size off;
# ------------------------------------
# "fancyindex" is not built into nginx
fancyindex on;
fancyindex_default_sort name;
fancyindex_directories_first on;
fancyindex_case_sensitive off;
fancyindex_exact_size off;
fancyindex_time_format "%Y-%m-%d %H:%M";
fancyindex_css_href "/css/nsr-folder-default.css";
try_files $uri $uri/ =404;
}
#
# this declaration affects all subseqent folders
#
location / {
# "autoindex" is built into nginx
# autoindex on;
# autoindex_exact_size off;
# ------------------------------------
# "fancyindex" is not built into nginx
fancyindex on;
fancyindex_default_sort name;
fancyindex_directories_first on;
fancyindex_case_sensitive off;
fancyindex_exact_size off;
fancyindex_time_format "%Y-%m-%d %H:%M";
fancyindex_css_href "/css/nsr-folder-default.css";
}
location /cgi-bin/ {
# Disable gzip so script outputs stream properly if needed
gzip off;
# The root directory where your 'cgi-bin' folder lives
# e.g., if files are in /var/www/html/cgi-bin/, set root to /var/www/html
root /var/www/html;
# Pass requests to the fcgiwrap Unix socket
# fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_pass unix:/run/fcgiwrap/fcgiwrap-nginx.sock;
# Include standard Nginx FastCGI parameters
include fastcgi_params;
# Map the exact script filename to be executed
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}

Back to
Home
Neil Rieck
Waterloo, Ontario, Canada.