NGINX as a Simple Web Server

Published 2024-07-30

Nginx is a simple web server — but sometimes you want something that is really simple to setup . You know, something like Python’s python3 -m http.server or Busybox’s httpd or Caddy which are all great options, but I like to focus on a single tool, really get to know it, and use it everywhere. So as I use nginx in production (as an edge router, for static file serving, etc) I use it for the simple need-a-server-now use case too.

So without more ado, here is how to do that.

Nginx needs a little bit for a basic config, so I store this minimal config somewhere on the host:

daemon off;
events {}
pid nginx.pid;
http {
include /etc/nginx/mime.types;
access_log /dev/stdout;
client_body_temp_path .;
proxy_temp_path .;
fastcgi_temp_path .;
uwsgi_temp_path .;
scgi_temp_path .;
server {
server_name localhost;
listen 0.0.0.0:8000;
location / {
autoindex on;
root public;
}
}
}

Then when I wan to serve a directory under Nginx, use:

nginx -p $PWD -e stderr -c /path/to/nginx.conf