I wanted nginx to serve CGI scripts from /usr/local/www/cgi-bin. Unlike Apache, nginx supports only FastCGI. Thus, you have to use fcgiwrap.
# make -C /usr/ports/www/nginx install clean
# make -C /usr/ports/www/fcgiwrap install clean
# mkdir /usr/local/www/cgi-bin
#!/bin/sh echo "Content-Type: text/plain" echo date
# chmod 0755 /usr/local/www/cgi-bin/test.sh
... http { ... server { ... location / { ... } location /cgi-bin { root /usr/local/www; include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock; } ... } ... } ...
# sysrc nginx_enable=YES # sysrc fcgiwrap_enable=YES # sysrc fcgiwrap_socket_group=www
# sysrc fcgiwrap_flags=-f
# service fcgiwrap start # service nginx start