Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Nginx – Dynamic SSI Example (nginx.com)
5 points by thunderbong on Jan 14, 2023 | hide | past | favorite | 3 comments


Naaah... try_files would be better. Something like:

  location / {
    ssi on;
    set $inc $request_uri;
    ssi_silent_errors on;
    try_files $uri $uri/ /ssi.html;
  }
ssi.html:

  <html>
    <body>
      <!--# if expr="$inc" != "/" -->
        <!--# include file="$inc.html" -->
      <!--# else -->
        <!--# include file="inc_index.html" -->
      <!--# endif -->
    </body>
  </html>


If I understand correctly, if I enter the URL example.com/abcd it will look for abcd.html and if doesn't find that it will look for abcd_index.html and finally dail quietly.

Did I get that right? Can you elaborate why this is better?


try_files will handle checking if the file already exists, if it doesn't it will use ssi.html which will then handle including the file. If there isn't a request for a specific file, e.g. https://example.com/, then it will include "inc_index.html" (that's just the string "inc" not a variable "$inc" and I'm comparing to "/" from memory, it might just need to be an empty "").

You could skip the "set $inc $request_uri" line and simply use $uri (that's the normalized URI) in ssi.html.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: