Nginx: Why the index directive can't work, 403 forbidden?

zhenguoli

The nginx.conf is as following:

user  www-data;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

events {
    worker_connections  1024;
}
http {
    server {
        listen 8080;
        server_name example.com;
        root /tmp/test/example;

        location = / {
            index index.html;
        }

        location / {
            root /tmp/test/mydomain;
        }
    }
}

The errors.log is:
2016/03/22 23:07:56 [error] 17763#0: *1 directory index of "/tmp/test/example/" is forbidden, client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", host: "example.com:8080"

But when I comment the line root /tmp/test/example, it works fine. So I want to know how the index redirect works?

Richard Smith

It seems to me that you do not have an index.html file in the /tmp/test/example directory.

Your location = / block tests for the presence of the file (index.html), and if it does not exist, generates a 403 response.

After the URI is rewritten to /index.html it is actually processed by your location / block.

I suspect that the reason it works when you delete the first root directive, is because the default (or global) root takes over where the "Welcome to nginx" index.html file is located. So, it passes the existence test, then serves your file.

I should add that the above is mostly guesswork based on your observations and my experiments.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Nginx 403 error: directory index of [folder] is forbidden

From Dev

nginx index directive does not work

From Dev

nginx 403 Forbidden error

From Dev

403 forbidden error at Nginx

From Dev

Apache 403 Directory index forbidden by Options directive, even with index.html

From Dev

Why 403 forbidden with curl where cookies seams to work?

From Dev

Why 403 forbidden with curl where cookies seams to work?

From Dev

jquery post method doesn't work (403 - Forbidden)

From Dev

always 403 Forbidden with Nginx .htpasswd

From Dev

403 Forbidden, Index of / catch 22

From Dev

403 Forbidden, Index of / catch 22

From Dev

Can't publish to Azure from VS 2013 RC (403 Forbidden)

From Dev

Ruby on Rails app can't query AWS - error 403 forbidden

From Dev

Nginx: 403 Forbidden nginx/1.12.1 (Ubuntu)

From Dev

Why am I getting 403 Forbidden status codes for static files served via nginx / php-fpm?

From Dev

403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel

From Dev

403 Forbidden on Rails app w/ Nginx, Passenger

From Dev

403 forbidden error, in Nginx configuration for Wordpress site

From Java

Nginx serve static file and got 403 forbidden

From Dev

Nginx is throwing an 403 Forbidden on Static Files

From Dev

Nginx does not serve image ( 403 - forbidden error )

From Dev

Linode Update - 403 Forbidden with Rails and Passenger Nginx

From Dev

403 Forbidden nginx/1.6.2 on Laravel Homestead installation

From Dev

Nginx config issue: getting 403 Forbidden

From Dev

403 forbidden error, in Nginx configuration for Wordpress site

From Dev

Nginx from source, return 403 Forbidden

From Dev

Nginx 403 Forbidden error on a simple conf file

From Dev

CentOS, Nginx: 403 Forbidden in Laravel's folder

From Dev

Why custom directive doesn't work

Related Related

  1. 1

    Nginx 403 error: directory index of [folder] is forbidden

  2. 2

    nginx index directive does not work

  3. 3

    nginx 403 Forbidden error

  4. 4

    403 forbidden error at Nginx

  5. 5

    Apache 403 Directory index forbidden by Options directive, even with index.html

  6. 6

    Why 403 forbidden with curl where cookies seams to work?

  7. 7

    Why 403 forbidden with curl where cookies seams to work?

  8. 8

    jquery post method doesn't work (403 - Forbidden)

  9. 9

    always 403 Forbidden with Nginx .htpasswd

  10. 10

    403 Forbidden, Index of / catch 22

  11. 11

    403 Forbidden, Index of / catch 22

  12. 12

    Can't publish to Azure from VS 2013 RC (403 Forbidden)

  13. 13

    Ruby on Rails app can't query AWS - error 403 forbidden

  14. 14

    Nginx: 403 Forbidden nginx/1.12.1 (Ubuntu)

  15. 15

    Why am I getting 403 Forbidden status codes for static files served via nginx / php-fpm?

  16. 16

    403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel

  17. 17

    403 Forbidden on Rails app w/ Nginx, Passenger

  18. 18

    403 forbidden error, in Nginx configuration for Wordpress site

  19. 19

    Nginx serve static file and got 403 forbidden

  20. 20

    Nginx is throwing an 403 Forbidden on Static Files

  21. 21

    Nginx does not serve image ( 403 - forbidden error )

  22. 22

    Linode Update - 403 Forbidden with Rails and Passenger Nginx

  23. 23

    403 Forbidden nginx/1.6.2 on Laravel Homestead installation

  24. 24

    Nginx config issue: getting 403 Forbidden

  25. 25

    403 forbidden error, in Nginx configuration for Wordpress site

  26. 26

    Nginx from source, return 403 Forbidden

  27. 27

    Nginx 403 Forbidden error on a simple conf file

  28. 28

    CentOS, Nginx: 403 Forbidden in Laravel's folder

  29. 29

    Why custom directive doesn't work

HotTag

Archive