Autoindex directive in 'if' section

Hello,

I would like to use the following in my conf file:
location a/ {
if ($host ~* “”) {
root “”;
autoindex on;
}
}

But that doesn’t work: ‘nginx: [emerg] “autoindex” directive is not
allowed
here’

What should I do?

Thanks,

B. R.

Hello!

On Thu, Jan 26, 2012 at 02:16:22PM -0500, B.R. wrote:

But that doesn’t work: ‘nginx: [emerg] “autoindex” directive is not allowed
here’

What should I do?

Maxim D.

I know this Wiki page…
I guess return/rewrite are useless here: I only want to change the root
and activate the directory listing when the user is on a specific
directory of a specific domain.

Any more help ? :\

Thx,
B.R.


De: Maxim D. [email protected]
: [email protected]
Envoy le : Jeudi 26 janvier 2012 14h21
Objet: Re: autoindex directive in ‘if’ section

Hello!

On Thu, Jan 26, 2012 at 02:16:22PM -0500, B.R. wrote:

But that doesn’t work: ‘nginx: [emerg] “autoindex” directive is not allowed
here’

What should I do?

Maxim D.

Thanks for the help!
Needed some other tricks playing with the path…

Many thanks again! ;o)

B. R.

28 января 2012, 00:44 от “[email protected]” : > I know this Wiki
page… > I guess return/rewrite are useless here: I only want to change
the root and > activate the directory listing when the user is on a
specific directory of a > specific domain. > > Any more help ? :\ I just
explained how this is handled here:
How to proxy_pass POST with headers In
your case use the rewrite inside the if block and and then change root
and set autoindex inside the internal URI block. Max

Erk…
Didn’t make all my tests :o)

To end the job, I need to get rid of the ‘post_rewrite’ part of the
path,
so my files get served as ‘/path/to/files’ and not
‘/post_rewrite/path/to/files’.
I tried rewrite, but of course that gets me out of the current location
block…

Should I replace the content of $uri? Is there any variable regex
substitution mechanism in nginx?
Couldn’t find that on Google nor wiki. Maybe I am not searching for the
right thing.

B. R.

So simple…
Thanks for everything Max, it works perfectly! ;o)

B. R.

Hello,

Finally, a little something still annoying me…

Since the location is based on the new /post_redirect/ folder, the
indexing
page shows:
Index of /post_redirect/*******

It is unaesthetic to me, since I would like the original URI there. :o
Any trick on that?

B. R.

28 января 2012, 03:11 от “B.R.” : > To end the job, I need to get rid of
the ‘post_rewrite’ part of the path, > so my files get served as
‘/path/to/files’ and not > ‘/post_rewrite/path/to/files’. > I tried
rewrite, but of course that gets me out of the current location >
block… > > Should I replace the content of $uri? Is there any
variable regex > substitution mechanism in nginx? > Couldn’t find that
on Google nor wiki. Maybe I am not searching for the > right thing.
http://wiki.nginx.org/HttpCoreModule#alias Use alias instead of root, it
does exactly what you need: location ~ ^/post_rewrite/(.*)$ { internal;
autoindex on; alias /sandbox/$1; } Max

02 февраля 2012, 01:46 от “B.R.” [email protected]:

Since the location is based on the new /post_redirect/ folder, the indexing page
shows:
Index of /post_redirect /*******

It is unaesthetic to me, since I would like the original URI there. :o
Any trick on that?

http://wiki.nginx.org/HttpLogModule

Set whatever log_format you want inside the /post_redirect/ location
block.

http://wiki.nginx.org/HttpCoreModule#log_subrequest

You can also turn log_subrequest off inside the if block
to prevent the rewrite from showing up in the logs.

Max

OK, thanks for the answer!

B. R.

02 февраля 2012, 01:46 от “B.R.” [email protected]:

Since the location is based on the new /post_redirect/ folder, the indexing
page shows:
Index of /post_redirect/*******

It is unaesthetic to me, since I would like the original URI there. :o
Any trick on that?

Sorry, I misunderstood your question. If you want autoindex to mask
the directory name, you’ll have to change the source code yourself:

File src/http/modules/ngx_http_autoindex_module.c
Function: ngx_http_autoindex_handler(ngx_http_request_t *r)
Variable: dir

You could extend the module to include a new command for
such masking (autoindex_mask_dir “/dir_to_display/”), it shouldn’t
take more than 20 minutes to code.

Max