Welcome! Log In Create A New Profile

Advanced

Trouble with autoindex on

Posted by siovene 
Trouble with autoindex on
July 07, 2009 07:14AM
Hello, I'm new to nginx, and I have just migrated from apache. I need to autoindex one directory on my server.

I have added this to my config:

[code]
location ^~ /svg/ {
autoindex on;
}
[/code]

The directory I need to index is www.my-server.com/svg/. Without that piece of configuration, I get 403, as expected, but with it I get 404.

Here's my full config for that server:

[code]
server {

listen 80;
server_name geekherocomic.com;
rewrite ^/(.*) http://www.geekherocomic.com/$1 permanent;

}


server {
listen 80;
server_name www.geekherocomic.com;

access_log /var/log/nginx/geekherocomic.com-access.log;
error_log /var/log/nginx/geekherocomic.com-error.log;

location ~* ^.+\.(css|js|jpg|png|ico|gif)$ {
root /var/www/geekherocomic.com/;

access_log off;
expires max;
}

location ^~ /svg/ {
autoindex on;
}

location / {

root /var/www/geekherocomic.com/;
index index.php index.html;

# Basic version of Wordpress parameters, supporting nice permalinks.
# include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of Wordpress parameters supporting nice permalinks and WP Super Cache plugin
include /etc/nginx/conf.d/wordpress_params.super_cache;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/geekherocomic.com/$fastcgi_script_name;
}
}
[/code]

Thanks for the help!
Salvatore.
Re: Trouble with autoindex on
July 07, 2009 02:38PM
Try changing

[code]
location ^~ /svg/ {
autoindex on;
}
[/code]

to

[code]
location /svg {
autoindex on;
}
[/code]

--
Jim Ohlstein



Edited 1 time(s). Last edit at 07/07/2009 02:39PM by Jim Ohlstein.
Re: Trouble with autoindex on
July 07, 2009 02:42PM
Hi Jim, thanks. But it's still 404.
Re: Trouble with autoindex on
July 07, 2009 03:10PM
That's odd.

If you go to http://files.worldwartwozone.com/ you will see the autoindex module in use. This is the exact config:

[code]
server {
listen 76.73.78.220:80;
server_name files.worldwartwozone.com;
#server_name_in_redirect on;
index index.php index.html;
root /home/jim/files.worldwartwozone.com/files;

location / {
autoindex on;
autoindex_exact_size off;
}
}
[/code]

Please post the output of

# nginx -V

--
Jim Ohlstein
Re: Trouble with autoindex on
July 07, 2009 03:13PM
Jim Ohlstein Wrote:
-------------------------------------------------------
> That's odd.
>
> If you go to http://files.worldwartwozone.com/ you
> will see the autoindex module in use. This is the
> exact config:
>
>
> server {
> listen 76.73.78.220:80;
> server_name files.worldwartwozone.com;
> #server_name_in_redirect on;
> index index.php index.html;
> root /home/jim/files.worldwartwozone.com/files;
>
> location / {
> autoindex on;
> autoindex_exact_size off;
> }
> }

It works for me too, on another host, if there's just one location and it's /.

> Please post the output of
>
> # nginx -V

nginx version: nginx/0.6.32
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module
Re: Trouble with autoindex on
July 07, 2009 03:33PM
OK, I was wondering if it had been built without the autoindex module. That would have been an easy fix and something easy to have overlooked.

I wonder if it's a bug in an earlier version as I am running 0.8.4. I do suggest you upgrade at least to latest stable version (0.7.61).

As a test, I created a subdirectory "test" in the above location and added a section to the site config file like so:

[code]
server {
listen 76.73.78.220:80;
server_name files.worldwartwozone.com;
#server_name_in_redirect on;
index index.php index.html;
root /home/jim/files.worldwartwozone.com/files;

location / {
autoindex on;
autoindex_exact_size off;
}

location /test {
autoindex on;
autoindex_exact_size off;
}

}
[/code]

I placed one file in there and you can see it at http://files.worldwartwozone.com/test/ .

So... I am puzzled.

--
Jim Ohlstein
Re: Trouble with autoindex on
December 01, 2009 01:52PM
try

[code]
location /test {
root /home/jim/files.worldwartwozone.com/files;
autoindex on;
autoindex_exact_size off;
}
[/code]
Re: Trouble with autoindex on
May 07, 2010 02:49AM
Hi,

I know this topic is old but I just found it while searching for solution for exactly the same problem. Finally I figured it out how to fix the 404 problem for autoindexing so I'm posting it so it'll maybe help someone someday :).
It seems that one have to move [b]root[/b] line out of [b]location[/b]s.
Here's my config before:
[code]
server {
listen 80;
server_name files.barszcz.info;
error_log /var/log/nginx/files.barszcz.info.error.log;
access_log /var/log/nginx/files.barszcz.info.access.log;

location ^~ /share {
#root /home/barszcz/www/files/share;
autoindex on;
autoindex_exact_size off;
}
location / {
root /home/barszcz/www/files;
if ($request_uri ~* "\.(ico|gif|png|jpe?g|css|js|swf|pdf)(\?[0-9]+)?$") {
expires 30d;
access_log off;
break;
}
}
}
[/code]
and after:
[code]
server {
listen 80;
server_name files.barszcz.info;
error_log /var/log/nginx/files.barszcz.info.error.log;
access_log /var/log/nginx/files.barszcz.info.access.log;

root /home/barszcz/www/files;

location ^~ /share {
autoindex on;
autoindex_exact_size off;
}
location / {
if ($request_uri ~* "\.(ico|gif|png|jpe?g|css|js|swf|pdf)(\?[0-9]+)?$") {
expires 30d;
access_log off;
break;
}
}
}
[/code]
Now it works :)



Edited 1 time(s). Last edit at 05/07/2010 02:52AM by barszcz.
Re: Trouble with autoindex on
July 14, 2010 12:27AM
barszcz Wrote:
-------------------------------------------------------
> Hi,
>
> I know this topic is old but I just found it while
> searching for solution for exactly the same
> problem. Finally I figured it out how to fix the
> 404 problem for autoindexing so I'm posting it so
> it'll maybe help someone someday :).
> It seems that one have to move root line out of
> locations.
> Here's my config before:
>
> server {
> listen 80;
> server_name files.barszcz.info;
> error_log
> /var/log/nginx/files.barszcz.info.error.log;
> access_log
> /var/log/nginx/files.barszcz.info.access.log;
>
> location ^~ /share {
> #root /home/barszcz/www/files/share;
> autoindex on;
> autoindex_exact_size off;
> }
> location / {
> root /home/barszcz/www/files;
> if ($request_uri ~*
> "\.(ico|gif|png|jpe?g|css|js|swf|pdf)(\?[0-9]+)?$"
> ) {
> expires 30d;
> access_log off;
> break;
> }
> }
> }
>
> and after:
>
> server {
> listen 80;
> server_name files.barszcz.info;
> error_log
> /var/log/nginx/files.barszcz.info.error.log;
> access_log
> /var/log/nginx/files.barszcz.info.access.log;
>
> root /home/barszcz/www/files;
>
> location ^~ /share {
> autoindex on;
> autoindex_exact_size off;
> }
> location / {
> if ($request_uri ~*
> "\.(ico|gif|png|jpe?g|css|js|swf|pdf)(\?[0-9]+)?$"
> ) {
> expires 30d;
> access_log off;
> break;
> }
> }
> }
>
> Now it works :)
Thank you for this!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 210
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready