Path to a directory should return 404

Under the document root, I have few directories like
/1/file1.html
/1/file2.html
/2/file1.html
/2/file2.html

If I go to the url http://localhost:8080/1, I get back a 301 with the
new location http://localhost/1/ autoindexing is off, and so I end
up with a 403 Forbidden page.

Can I change this default behavior such that all the requests for the
directories get the universal 404 page i.e. instead of a redirection, it
should simply return the configured 404 page for location /.

Sorry, I couldn’t find a similar post on the forums. Thanks for any
pointers.

Posted at Nginx Forum:

On Mon, Nov 07, 2011 at 05:22:29PM -0500, nchainani wrote:

Can I change this default behavior such that all the requests for the
directories get the universal 404 page i.e. instead of a redirection, it
should simply return the configured 404 page for location /.

Sorry, I couldn’t find a similar post on the forums. Thanks for any
pointers.

Something like that maybe?

: location / {
: #error_page 404 …;
: location ~ /$ { return 404; }
: }