I have this server block:
server {
listen 80;
server_name admin.app;
root /opt/project/public/src/;
charset utf-8;
location ~ ^/dashboard/?(.*)$ {
alias /opt/project/dashboard/src;
try_files /$1 /testindex.html;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/project.app-error.log debug;
rewrite_log on;
}
and this dir structure:
/opt/project/dashboard/src/
test.svg
testindex.html
When I go to http://localhost/dashboard/test.svg
it works fine,
but if I goto http://localhost/dashboard/testing
I want it to serve /opt/project/dashboard/src/
but instead the debug shows this:
2017/06/16 19:36:11 [debug] 385#0: *46 http request line: "GET /dashboard/testing HTTP/1.1"
2017/06/16 19:36:11 [debug] 385#0: *46 http uri: "/dashboard/testing"
2017/06/16 19:36:11 [debug] 385#0: *46 http script copy: "/opt/project/dashboard/src/"
2017/06/16 19:36:11 [debug] 385#0: *46 http script capture: "testing"
2017/06/16 19:36:11 [debug] 385#0: *46 trying to use file: "testing" "/opt/project/dashboard/src/testing"
2017/06/16 19:36:11 [debug] 385#0: *46 trying to use file: "testindex.html" "/opt/project/dashboard/src/testindex.html"
2017/06/16 19:36:11 [debug] 385#0: *46 internal redirect: "testindex.html?"
2017/06/16 19:36:11 [debug] 385#0: *46 rewrite phase: 1
2017/06/16 19:36:11 [debug] 385#0: *46 test location: "/robots.txt"
2017/06/16 19:36:11 [debug] 385#0: *46 test location: ~ "^/dashboard/?(.*)$"
2017/06/16 19:36:11 [debug] 385#0: *46 using configuration ""
2017/06/16 19:36:11 [debug] 385#0: *46 http filename: "/opt/project/public/src/testindex.html"
(relevant parts of log only for brevity)
And it gives a 404 (or will serve the wrong file if I do put it into public/src
). It shows it tested the existing testindex.html file, but then goes off redirects and tries to serve it from the public/src
dir. I don't want it to serve anything from public/src
at that path. Why won't it send the testindex.html
in dashboard/src
? I've been struggling with this for hours trying many different configurations.
EDIT:
I changed the try_files to: try_files /$1 /dashboard/testindex.html;
. This was the result:
2017/06/16 20:04:08 [debug] 464#0: *65 trying to use file: "/dashboard/testindex.html" "/opt/project/dashboard/src/dashboard/testindex.html"
2017/06/16 20:04:08 [debug] 464#0: *65 internal redirect: "/dashboard/testindex.html?"
2017/06/16 20:04:08 [debug] 464#0: *65 rewrite phase: 1
2017/06/16 20:04:08 [debug] 464#0: *65 test location: ~ "^/dashboard/?(.*)$"
2017/06/16 20:04:08 [debug] 464#0: *65 using configuration "^/dashboard/?(.*)$"
2017/06/16 20:04:08 [debug] 464#0: *65 try files phase: 11
2017/06/16 20:04:08 [debug] 464#0: *65 http script copy: "/opt/project/dashboard/src"
2017/06/16 20:04:08 [debug] 464#0: *65 http script copy: "/"
2017/06/16 20:04:08 [debug] 464#0: *65 http script capture: "testindex.html"
2017/06/16 20:04:08 [debug] 464#0: *65 trying to use file: "/testindex.html" "/opt/project/dashboard/src/testindex.html"
2017/06/16 20:04:08 [debug] 464#0: *65 try file uri: "/testindex.html"
2017/06/16 20:04:08 [debug] 464#0: *65 http script copy: "/opt/project/dashboard/src"
2017/06/16 20:04:08 [debug] 464#0: *65 http filename: "/opt/project/dashboard/src/testindex.html"
And it seems to be working, but I don't understand what's happening, it's still doing the redirect, but it's looking at the wrong path, so not sure how it's getting it right or what's up with it. @confused