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?
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.
Comments