How to browse by web a folder under nginx environnement

September 18, 2014 2.9k views

Hi all,

i've created trough sftp another folder near my ghost folder in nginx environnment:
/var/www/ghost
/var/www/folderx

Ghost works find but i don't find out how to acess the folderx trough http://myurl.tld/folderx

Used to an apache environment i don't see how to do this under nginx.

Could you help ?

Thx

SPG

4 comments
  • Hi. Is the folder /var/www/ghost accessible trough myurl.tld or myurl.tld/ghost? What type of error message do you see when you try to access myurl.tld/folderx?

  • /var/www/ghost is accessible through myurl.tld.
    When i try to access myurl.tld/folderx i get a 404 error.

  • I've tried to add

     location /folder/ {
        alias /var/www/folder/;
      }
    

    in my etc/nginx/sites-enabled/ghost file
    and restarting ghost but it doesnt work

  • I think i'm getting somewhere now as i got a 403 Forbidden error now.
    and with adding

    location /folder/ {
    alias /var/www/folder/;
    autoindex on;
    }

    i can list the folder without being able to access its content...

3 Answers

It sounds like you're pretty close. You can set this up with an alias directive in your Nginx configuration:

server {
    listen 80 default_server;

    server_name my-ghost-blog.com;

    root /var/www/ghost;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:2368;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }

    location /folder/ {
            alias /var/www/folder/;
            autoindex on;
    }
}

The key thing here for being able to browse through the directory structure is the addition of autoindex on Also, make sure the folder has the correct permissions:

sudo chown -R www-data:www-data /var/www/folder/
  • Thx Andrew !

    1) I missed the root /var/www/ghost; line
    which was root /usr/share/nginx/html; for some reason !

    2) restored the root /usr/share/nginx/html; as ghost was not working anymore; Restarted ghost and nginx, and it's workings. I think it was the folder permissions !

    Problem solved !

Add an index.html and try to access it myurl.tld/folderx/index.html

What do the NGINX error logs have to say ? Could you share your logs ?

  • 2014/09/18 07:22:35 [error] 16047#0: *1 directory index of "/var/www/emissions/" is forbidden, client: 195.244.XXX.XX, server: pbg.xyz, request: "GET /emissions/ HTTP/1.1", host: "www.pbg.xyz"

    2014/09/18 07:22:38 [error] 16047#0: *1 directory index of "/var/www/emissions/" is forbidden, client: 195.244.XXX.XX, server: pbg.xyz, request: "GET /emissions/ HTTP/1.1", host: "www.pbg.xyz"

    2014/09/18 07:22:52 [error] 16047#0: *1 directory index of "/var/www/emissions/" is forbidden, client: 195.244.XXX.XX, server: pbg.xyz, request: "GET /emissions/ HTTP/1.1", host: "www.pbg.xyz"

  • It's working on index.html, not on the rest of the content...
    maybe something related to the ftp user... as index is own by root and work and not the subcontent with the ftp user as an owner

  • Do the other directories contain index.html files too? Is there a file called index.html in /var/www/emissions?

Have another answer? Share your knowledge.