Why do I need a `try_files` to make the `root` directive work?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I was having troubles making nginx find the static files for my frontend, and in what I thought was a desperate effort, I added a seemingly-tautological try_files
instruction, which made everything work.
location /frontend
try_files $uri /;
root static_root ;
index /frontend/index.html;
location /
rewrite ^.*$ /frontend/index.html break;
My question is: why wouldn't this work without the first location /frontend
directive?
nginx
add a comment |Â
up vote
2
down vote
favorite
I was having troubles making nginx find the static files for my frontend, and in what I thought was a desperate effort, I added a seemingly-tautological try_files
instruction, which made everything work.
location /frontend
try_files $uri /;
root static_root ;
index /frontend/index.html;
location /
rewrite ^.*$ /frontend/index.html break;
My question is: why wouldn't this work without the first location /frontend
directive?
nginx
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I was having troubles making nginx find the static files for my frontend, and in what I thought was a desperate effort, I added a seemingly-tautological try_files
instruction, which made everything work.
location /frontend
try_files $uri /;
root static_root ;
index /frontend/index.html;
location /
rewrite ^.*$ /frontend/index.html break;
My question is: why wouldn't this work without the first location /frontend
directive?
nginx
I was having troubles making nginx find the static files for my frontend, and in what I thought was a desperate effort, I added a seemingly-tautological try_files
instruction, which made everything work.
location /frontend
try_files $uri /;
root static_root ;
index /frontend/index.html;
location /
rewrite ^.*$ /frontend/index.html break;
My question is: why wouldn't this work without the first location /frontend
directive?
nginx
asked May 2 at 16:18
mccc
1134
1134
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The rewrite
is a indiscriminate, it applies to every request (even .css
and .js
files). By adding a separate location
, URIs beginning with /frontend
are protected from the indiscriminate rewrite
.
You could probably achieve a similar result with:
root /path/to/root;
location /
try_files $uri $uri/ /frontend/index.html;
See this document for more.
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The rewrite
is a indiscriminate, it applies to every request (even .css
and .js
files). By adding a separate location
, URIs beginning with /frontend
are protected from the indiscriminate rewrite
.
You could probably achieve a similar result with:
root /path/to/root;
location /
try_files $uri $uri/ /frontend/index.html;
See this document for more.
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
add a comment |Â
up vote
0
down vote
accepted
The rewrite
is a indiscriminate, it applies to every request (even .css
and .js
files). By adding a separate location
, URIs beginning with /frontend
are protected from the indiscriminate rewrite
.
You could probably achieve a similar result with:
root /path/to/root;
location /
try_files $uri $uri/ /frontend/index.html;
See this document for more.
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The rewrite
is a indiscriminate, it applies to every request (even .css
and .js
files). By adding a separate location
, URIs beginning with /frontend
are protected from the indiscriminate rewrite
.
You could probably achieve a similar result with:
root /path/to/root;
location /
try_files $uri $uri/ /frontend/index.html;
See this document for more.
The rewrite
is a indiscriminate, it applies to every request (even .css
and .js
files). By adding a separate location
, URIs beginning with /frontend
are protected from the indiscriminate rewrite
.
You could probably achieve a similar result with:
root /path/to/root;
location /
try_files $uri $uri/ /frontend/index.html;
See this document for more.
answered May 2 at 16:48
Richard Smith
771148
771148
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
add a comment |Â
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
Thanks! I guess I'll leave it as it is now since it's a tad more explicit
â mccc
May 3 at 8:15
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441356%2fwhy-do-i-need-a-try-files-to-make-the-root-directive-work%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password