As title descript,when i request for "http://example.com/test/poster/",i want to get the real file "/home/vagrant/example/resouces/views/posters.html".
Here is my nginx configuration:
server_name example.com;
root /home/vagrant/example/public;
index index.html;
location / {
return 404;
}
location ~ ^/test/poster/?$ {
default_type text/html;
index posters.html;
alias /home/vagrant/example/resouces/views/;
}
But when i make the request,i get a 404 response.I search for the nginx error log,i get the info below:
2018/10/20 11:54:41 [debug] 4690#4690: *180 http script copy: "/home/vagrant/example/resouces/views/"
2018/10/20 11:54:41 [debug] 4690#4690: *180 open index "/home/vagrant/example/resouces/views/posters.html"
2018/10/20 11:54:41 [debug] 4690#4690: *180 internal redirect: "/test/poster/posters.html?"
2018/10/20 11:54:41 [debug] 4690#4690: *180 rewrite phase: 1
Here is my question,when open index,it has find the file,why does it act a internal redirect?
I finally resolve it by using try_files,i just want to know why it dose not work when i use alias with index in one location block.Thanks!
The index module performs a multistage process.
If the URI ends with a / and is found to be a directory within the location that is currently processing the request, Nginx will check for a file matching a name in the index directive's value.
If a matching file is found, the URI will be changed by appending that name, and the search for a location to process the new URI will commence.
In your case, the URI /test/poster/posters.html does not match the original location and therefore the posters.html file is not found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With