Files
nginx-serve/conf/sqlite_serve.conf
Edward Langley 56c6045e3b Use ngx_log_error! macro and fix formatting
- Switched from ngx_log_error_core() to ngx_log_error! macro
- Changed error_log level from debug to info (cleaner output)
- Formatting cleanup across all modules (cargo fmt)
- Removed trailing newlines and fixed indentation

Logging now properly uses nginx's macro system for better
integration with nginx's log handling.
2025-11-15 17:16:55 -08:00

115 lines
3.7 KiB
Plaintext

# sqlite-serve - Unified Production Example
# Demonstrates all features: static queries, positional params, named params, templates
load_module target/debug/libsqlite_serve.dylib;
worker_processes auto;
events {
worker_connections 1024;
}
error_log logs/error.log info;
http {
# Global templates for shared components
sqlite_global_templates "server_root/global_templates";
# MIME types
types {
text/html html htm;
text/css css;
application/javascript js;
}
default_type text/html;
# Performance optimizations
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
server {
listen 8080;
server_name localhost;
root "server_root";
charset utf-8;
# Serve static CSS file
location /static/ {
add_header "Content-Type" "text/css; charset=utf-8";
add_header "Cache-Control" "public, max-age=31536000";
}
# Homepage - Redirect to catalog
location = / {
return 302 /books;
}
# Browse all books
location = /books {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
sqlite_template "catalog.hbs";
}
# Book detail by ID (named parameter)
location = /book {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE id = :book_id";
sqlite_param :book_id $arg_id;
sqlite_template "detail.hbs";
}
# Filter by genre (named parameter)
location = /genre {
add_header "Content-Type" "text/html; charset=utf-8";
add_header "Cache-Control" "public, max-age=300";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE genre = :genre ORDER BY rating DESC, title";
sqlite_param :genre $arg_genre;
sqlite_template "catalog.hbs";
}
# Search by title (named parameter with LIKE)
location = /search {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE title LIKE '%' || :q || '%' ORDER BY rating DESC";
sqlite_param :q $arg_q;
sqlite_template "catalog.hbs";
}
# Filter by minimum rating (named parameter)
location = /top {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE rating >= :min_rating ORDER BY rating DESC, title";
sqlite_param :min_rating $arg_min;
sqlite_template "catalog.hbs";
}
# Year range filter (multiple named parameters)
location = /era {
add_header "Content-Type" "text/html; charset=utf-8";
sqlite_db "book_catalog.db";
sqlite_query "SELECT * FROM books WHERE year >= :from AND year <= :to ORDER BY year DESC, title";
sqlite_param :from $arg_from;
sqlite_param :to $arg_to;
sqlite_template "catalog.hbs";
}
# 404 handler
location @notfound {
add_header "Content-Type" "text/html; charset=utf-8";
return 404 "<html><body><h1>404 Not Found</h1><p><a href='/books'>Back to catalog</a></p></body></html>";
}
}
}