nginx.conf — HTTP service and reverse proxy
Nginx organizes configuration into contexts. http contains server blocks, which select listeners and host names; location chooses a request handler. A proxy_pass URI can replace the matching prefix: in the simple prefix example /api/report becomes /report upstream. Without a URI the behavior differs; regex locations, rewrites and variables have additional restrictions. Includes are parsed at their placement and inheritance depends on each directive. Set deliberate listener addresses and upstream timeouts; do not assume the demo provides TLS or authorization. nginx -t parses and attempts to open referenced files; use a private prefix, logs and pid path, not the host configuration. No worker is started by -t; it can still create an empty PID file, logs and temporary directories. In real operations validate the full candidate, perform an approved reload, verify routing, certificates and readiness, and restore/reload the last working config if needed.
Formal Syntax & Structure
events {}http { server { listen 127.0.0.1:18080; location /api/ { proxy_pass http://127.0.0.1:18081/; } }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| server | directive or field | Virtual server context |
| listen | directive or field | Address and port |
| location | directive or field | Request matching context |
| proxy_pass | directive or field | Upstream URI |
Return Value
Native syntax/file-access check, not a live HTTP test.
Working Example
set -eud=$(mktemp -d)trap 'rm -rf -- "$d"' EXITcat > "$d/nginx.conf" <<EOFpid $d/nginx.pid;error_log $d/error.log;events {}http { access_log off; client_body_temp_path $d/body; proxy_temp_path $d/proxy; fastcgi_temp_path $d/fastcgi; uwsgi_temp_path $d/uwsgi; scgi_temp_path $d/scgi; server { listen 127.0.0.1:18080; location /api/ { proxy_pass http://127.0.0.1:18081/; } }}EOFnginx -t -p "$d/" -c "$d/nginx.conf" -e "$d/error.log" > "$d/check" 2>&1grep -F 'test is successful' "$d/check" >/dev/nulltest ! -s "$d/nginx.pid"printf 'private nginx configuration accepted; no daemon started\n'