0

I need to serve static file (index.html) with react running on it to everybody except google, facebook & twitter (plus some short list of other good bots).

My idea was to use something like

   if ($http_user_agent!~* (Google|Facebot|Twitterbot)) 
   {
        try_files $uri $uri/ /index.html;
   }
   proxy_pass http://127.0.0.1:3003/;
   ...

Nice solution but apparently if is evil and I can not use try_files inside of it (getting an error on config launch). I tried to reverse logic and do proxy_pass inside if, but the result is the same.

What is preferred way to solve this situation?

Amantel
  • 101
  • You can certainly do `proxy_pass` inside `if`in `location`. – Michael Hampton Apr 18 '19 at 16:58
  • Weird. Yesterday I got an error, but I will try to do it today. – Amantel Apr 19 '19 at 11:00
  • Sorry, it took more time to get to that situation, than I expected. I changed proxy_pass and try and this is the error I was refering too - nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in ... – Amantel Apr 22 '19 at 07:43

0 Answers0