Why do I need a `try_files` to make the `root` directive work?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question























    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?







    share|improve this question





















      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?







      share|improve this question











      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?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 2 at 16:18









      mccc

      1134




      1134




















          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.






          share|improve this answer





















          • Thanks! I guess I'll leave it as it is now since it's a tad more explicit
            – mccc
            May 3 at 8:15










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          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.






          share|improve this answer





















          • Thanks! I guess I'll leave it as it is now since it's a tad more explicit
            – mccc
            May 3 at 8:15














          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.






          share|improve this answer





















          • Thanks! I guess I'll leave it as it is now since it's a tad more explicit
            – mccc
            May 3 at 8:15












          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.






          share|improve this answer













          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.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          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
















          • 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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay